Jump to content

About CodeIgniter Logic.


Recommended Posts

Hi guys, I started learning PHP for 3-4 months already and just learned the basics so I still have more to learn. I came across frameworks just recently specifically CI. I was thinking the best way to learn PHP would be to analyse frameworks so I want to learn how CI does this:


$this->load->view("html") : Parent -> PHP file (not sure) -> method()


Would anyone care to explain how does it work. I would appreciate even just a simple detail from other sources, just give me a place to begin with understanding the logic. Right now, I'm learning a lot of stuffs from CI and I'm thankful for those people who are making it. It's a powerful framework.


Thank You.

Link to comment
Share on other sites

Please, don't like at CI for coding tips, it's not the best designed framework around.


You might also want to post an actual example of the code you want to understand. What you have posted is not valid php.


Are you referring to this part alone?

That is pretty straight forward. $this->load is an object, and the code calls the view() method on that object passing it the string 'html'. Keep in mind that view() may indeed not exist, and this code may actually trigger the load objects __call() method instead.


What it actually does, I wouldn't know. I wouldn't touch CI with a barge pole. My guess, load is some form of class loader and view() is indeed calling __call() which probably returns a html based view object.


When looking at code like this and trying to figure out what it does its a good idea to follow the code. You know that $this refers to the current object so start there. Can you find a property called $view. Where is it defined and what is assigned to it? Once you know that, you can look at the class that this object refers to and try and locate the view() method. If that method does not exist, look for the magic __call method instead.


See here: http://www.php.net/manual/en/language.oop5.overloading.php#object.call to understand what __call does.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • 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.