Ninjakreborn Posted April 6, 2007 Share Posted April 6, 2007 I recently shut down my framework for open public display. atleast until I know OOP/MVC front to back. Instead I have gutted a bunch of classes from Code Igniter, and a few other places, to start carrying classes around instead of just a framework. Right now I have the image library class. I named it class.image.php I required it into the page using require_once when I try to access it's functionality it returns an error. I used <?php $config['image_library'] = 'GD'; $config['source_image'] = "proofs/" . $row['imagename'] . "\""; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 75; $config['height'] = 50; $this->image_lib->resize(); ?> It threw out Fatal error: Call to a member function on a non-object in /home/content/d/e/s/designguru/html/clients/client.php on line 75 It's essentially the exact same class that was in code igniter, I eventually plan on learning how to use all of these, and learning how these classes work, then recreating my own sometime in the future. Is there something different I need to do to load a class. I have about 8 different pages of classes (class.file.php, class.array.php and so forth. I have them all required into the page, does that mean I won't be able to use any of those either. What am I doing wrong, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/ Share on other sites More sharing options...
Ninjakreborn Posted April 6, 2007 Author Share Posted April 6, 2007 I did some more looking into the files, and found the loader. I don't want to move into using a loader in my framework yet (I took it off mainstream the site is down and everything. I want to learn the standard way and later build up to using a loader class. Right now I have $imagelib = new CI_Image_lib() config['image_library'] = 'GD'; config['source_image'] = "proofs/" . $row['imagename'] . "\""; config['create_thumb'] = TRUE; config['maintain_ratio'] = TRUE; config['width'] = 75; config['height'] = 50; $this->image_lib->initialize($config); $this->image_lib->resize(); But it's throwing me this Parse error: parse error, unexpected T_STRING in /home/content/d/e/s/designguru/html/clients/client.php on line 69 Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-223122 Share on other sites More sharing options...
Ninjakreborn Posted April 6, 2007 Author Share Posted April 6, 2007 Sorry, here is my other code <?php $imagelib = new CI_Image_lib(); $config['image_library'] = 'GD'; $config['source_image'] = "proofs/" . $row['imagename'] . "\""; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 75; $config['height'] = 50; $this->image_lib->initialize($config); $this->image_lib->resize(); ?> I am now getting Fatal error: Call to a member function on a non-object in /home/content/d/e/s/designguru/html/clients/client.php on line 76 Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-223123 Share on other sites More sharing options...
Ninjakreborn Posted April 6, 2007 Author Share Posted April 6, 2007 Did some more learning. I saw now how to go ahead and set variables in OOP, and how to call functions. So I restructed my code to <?php $imagelib = new CI_Image_lib(); $imagelib->$image_library = 'GD'; $imagelib->source_image = "proofs/" . $row['imagename'] . "\""; $imagelib->create_thumb = TRUE; $imagelib->maintain_ratio = TRUE; $imagelib->width = 75; $imagelib->height = 50; $image_lib->initialize($config); $image_lib->resize(); ?> However it's still throwing that same error. Fatal error: Call to a member function on a non-object in /home/content/d/e/s/designguru/html/clients/client.php on line 76 Line 76 is the line that reads $image_lib->initialize(); Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-223127 Share on other sites More sharing options...
Ninjakreborn Posted April 6, 2007 Author Share Posted April 6, 2007 <?php $imagelib = new CI_Image_lib(); $config['image_library'] = 'GD'; $config['source_image'] = "proofs/" . $row['imagename'] . "\""; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 75; $config['height'] = 50; $image_lib->initialize($config); $image_lib->resize(); ?> After using this I know for a fact everything below the loading is correct. There is something wrong with the way I am trying to load the class. I know it's also instantiating it properly because when I try one that isn't there it comes back as (cannot load non-instantiated class). well when I load the right one which is as above, it returns. Fatal error: Call to a member function on a non-object in /home/content/d/e/s/designguru/html/clients/client.php on line 76 Which let's me know it's actually instantiating the class, but not allowing me to call the function. What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-223141 Share on other sites More sharing options...
redbullmarky Posted April 6, 2007 Share Posted April 6, 2007 What am I doing wrong? umm - trying to use CodeIgniters classes without fully understanding them/OOP, etc? Dude - save yourself the trouble. CodeIgniter is strong enough on its own: a) it'll let you build client sites b) it'll teach you a good deal about OOP and MVC c) it's structured well enough that, when you're ready, you can build your own framework so that porting your existing sites to your f/w from CodeIgniter shouldnt be too difficult. I did this with CakePHP and now have a framework where there'd be minimal fuss porting my sites to Cake and vice versa. Run before you can walk and just get on with using a tool that's good enough to do the trick. At the moment it seems like you're trying to write a framework at 2000 miles per hour without understanding ANY of the principles or reasons behind doing so - resulting in rewrite after restructure after rewrite after restructure after .... blah - like I keep telling you - slow the hell down! Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-223224 Share on other sites More sharing options...
Nameless12 Posted April 7, 2007 Share Posted April 7, 2007 I have to disagree with points b and c when it comes to B I think its better to learn something as opposed to learning how to use it. And when it comes to point C I think making a clone of code igniter with the goal of "Porting code" is pointless. If you are just going to do a copy so something can be "ported" then there is no point in making it in the first place and you should just use\extend upon the original code. I just really don't think code should be "ported" from framework to framework unless it is really simple functions that are used as an extension of the framework. Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-223543 Share on other sites More sharing options...
Jenk Posted April 8, 2007 Share Posted April 8, 2007 Learning the purpose is needed before learning the mechanics. You can't teach someone how to construct an engine if they don't know it will be used to generate motion. Same goes for programming. You can't just tell someone to create a class/object until they understand the requirements of said object, and the purpose for it. Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-224309 Share on other sites More sharing options...
btherl Posted April 9, 2007 Share Posted April 9, 2007 $imagelib != $image_lib Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-224743 Share on other sites More sharing options...
Ninjakreborn Posted April 9, 2007 Author Share Posted April 9, 2007 Thanks for all the advice. Right now what I was thinking is I dumped my framework for the public until I am A LOT better at OOP and MVC. The thing I am trying to do now was create a simple include file (Not a framework). Your right, I could just use Code Igniter. For now however I wanted to just get some classes together, but I found out why I was having problems. The reason is, because I am trying to get something more lightweight. Something where I can get associated with JUST classes, and modifying classes without a framework. I wanted to get good with OOP then go ahead and get into code igniter, and use it for a few projects to understand MVC. I can't understand MVC without OOP (that I knew of). Thanks for all the feedback. Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-224961 Share on other sites More sharing options...
btherl Posted April 10, 2007 Share Posted April 10, 2007 Did you get the point of my previous post? The reason PHP doesn't recognize $image_lib as an object is because $imagelib is the object.. without the underscore. It's a very common mistake to make in a language that doesn't require declaration of variables. Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-225491 Share on other sites More sharing options...
Ninjakreborn Posted April 27, 2007 Author Share Posted April 27, 2007 Yes, I realized that awhile after reading it. In the end I found out it's because of the class I was trying to take had functions that were dependent on other files, so it didn't work even after changing that. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/45934-solved-loading-a-class/#findComment-239759 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.