Help! OOP in CodeIgniter?

#1
[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.

#2
[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.

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

Search the forums for MY_Controller and then for _remap()

#4
[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?

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

#6
[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;

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

#8
[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!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.