![]() |
extending the controller class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: extending the controller class (/showthread.php?tid=30233) |
extending the controller class - El Forum - 05-07-2010 [eluser]Doodlez[/eluser] I have a certain number of elements that are going to be called on my page over and over again. I planned on extending the controller class with functions that generate the elements. For example my header is static with a few small changes.... Code: <?php and then any time I needed my header I can call it ............ Code: <?php my plan is to just create the other elements of my page as functions and just keep extending the controller class. I have never really done any object based programming I kind of guessed my way. Is there any where I will get my self in trouble creating a site like this? extending the controller class - El Forum - 05-07-2010 [eluser]jedd[/eluser] Hi Doodlez, [quote author="Doodlez" date="1273244440"] I planned on extending the controller class with functions that generate the elements. [/quote] You might want to get comfortable with using the built-in way of extending the core controller class - read about it [url="/wiki/MY_Controller"]in the wiki[/url]. extending the controller class - El Forum - 05-09-2010 [eluser]Doodlez[/eluser] Ok I can now call my functions as $this and don't have to call them using parent. It is late and it may be obvious but why the way I did it originally did I need to call the method as the parent and not class. It may be naive but the way I did it and your tutorial suggest appear to be the same thing. Is it the way that CI uses the MY_ namespace internally or something like that? I know I may not be wording this question well. extending the controller class - El Forum - 05-09-2010 [eluser]jedd[/eluser] [quote author="Doodlez" date="1273420871"] It may be naive but the way I did it and your tutorial suggest appear to be the same thing. Is it the way that CI uses the MY_ namespace internally or something like that? [/quote] Yes - it's configurable, and defaults to MY_ - have a read about it in the [url="/user_guide/general/creating_libraries.html"]User Guide section on creating libraries[/url]. extending the controller class - El Forum - 05-09-2010 [eluser]Phil Sturgeon[/eluser] $this and parent do pretty much the same thing, just one is more specific. When you extend a parent class you pick up all it's properties and methods, so parent::head() and $this->head() are identical. If you have head() in both parent and current THEN it would be different. |