Jump to content

[SOLVED] Loading a class


Ninjakreborn

Recommended Posts

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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();

Link to comment
Share on other sites

<?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?

Link to comment
Share on other sites

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! ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.