CodeIgniter Forums
Help! OOP in CodeIgniter? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Help! OOP in CodeIgniter? (/showthread.php?tid=11579)



Help! OOP in CodeIgniter? - El Forum - 09-14-2008

[eluser]ryepdx[/eluser]
I'm trying to change the Controller class so that all the classes that extend it automatically inherit a certain set of functions. For some reason though, this doesn't seem to be working. For example, I tried adding an index function to the Controller class, just to test things out. I made sure that the inheriting class didn't have an index function. I tried accessing the function and got a 404. Then I moved the function into the inheriting class and refreshed. The 404 went away and it worked.
After that I tried putting an echo statement at the end of the Controller class declaration to make sure I was editing the right file. Sure enough, the echo came back. Undecided

Has anybody come across this before? Do you know why this is happening? More importantly, is there any way I can accomplish what I'm trying to accomplish?
Thanks.


Help! OOP in CodeIgniter? - El Forum - 09-14-2008

[eluser]ryepdx[/eluser]
Also, does anyone know how to change the code so that functions preceded by a *double* underscore *can* get served? Specifically, I'm trying to use the __call function in PHP5 to dynamically handle requests from the URL that have not been specifically hard coded into the classes.


Help! OOP in CodeIgniter? - El Forum - 09-14-2008

[eluser]wiredesignz[/eluser]
Hi ryepdx, Welcome to CI forums

Search the forums for MY_Controller and then for _remap()


Help! OOP in CodeIgniter? - El Forum - 09-14-2008

[eluser]ryepdx[/eluser]
Got it! Wow, I'd read that part of the guide before too...
Thanks!

By the way, I noticed that the remap function only receives the method name. Is is possible for it to get the URL arguments too?


Help! OOP in CodeIgniter? - El Forum - 09-14-2008

[eluser]wiredesignz[/eluser]
Again search the forums, this time for URI or uri->segment.


Help! OOP in CodeIgniter? - El Forum - 09-14-2008

[eluser]ryepdx[/eluser]
Sweet! Thanks. I'm good to go now. :-)

Here's the code I ended up using to retrieve the URL arguments:
$args = load_class("URI")->segments;


Help! OOP in CodeIgniter? - El Forum - 09-14-2008

[eluser]wiredesignz[/eluser]
The uri class is already available to your controllers, so there's no real point in loading it again.


Help! OOP in CodeIgniter? - El Forum - 09-14-2008

[eluser]ryepdx[/eluser]
Got it. I saw on the post that I found that they were loading it, so that's why I did it.
The code now reads:
$args = $this->uri->segments;

Thanks again!