Integralist Posted February 17, 2009 Share Posted February 17, 2009 Hello, I'm new to PHP and wanted to write a Class that searched a directory looking for images and then displayed them on a web page at a specific size and a set number of images per page (with next and prev buttons) - ON A SIDE NOTE IF ANYONE KNOWS HOW TO DO THIS THEN CAN THEY HELP. So I started with a simple Class (see code below) but for some odd reason I cannot access the private member properties? Any help appreciated! M. class ClassGallery { // Private Properties private $directory = 'test'; private $imagesPerPage = 10; public function _construct($dir, $count) { // $directory = $dir; // $imagesPerPage = $count; } public function display() { echo($directory . ' / ' . $imagesPerPage); } } I'm using this code on the front-end page <?php include('Class.Gallery.php'); $gallery = new ClassGallery('images', 20); $gallery->display(); ?> Link to comment https://forums.phpfreaks.com/topic/145530-help-with-basic-classpublic-property-access/ Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 Use $this to access methods and functions of current object. public function display() { echo($this->directory . ' / ' . $this->imagesPerPage); } Link to comment https://forums.phpfreaks.com/topic/145530-help-with-basic-classpublic-property-access/#findComment-764045 Share on other sites More sharing options...
Integralist Posted February 17, 2009 Author Share Posted February 17, 2009 Hi there, Thank you for the quick response! that has helped display the private member properties. Do you know of a way to read a directory so it only reads in images? Kind regards, M. Link to comment https://forums.phpfreaks.com/topic/145530-help-with-basic-classpublic-property-access/#findComment-764075 Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 Never did that. Probably only by checking file extensions. Ask this in new topic. Link to comment https://forums.phpfreaks.com/topic/145530-help-with-basic-classpublic-property-access/#findComment-764077 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.