controller inherit syntax? |
[eluser]überfuzz[/eluser]
I'm setting up a small website, 4 pages. I figured that one controller would be enough. Is it possible to make the classes inherit stuff. Example, see question in the code: Code: class Hem extends Controller
[eluser]Dam1an[/eluser]
The easiest way to do it would be create a master controller (MY_Controller.php in the libraries folder) and extend that, you can then put in all common contructor code in there. You would then have to have MY_Controller extends the normal controller so you still have all the CI functionality
[eluser]überfuzz[/eluser]
Hmm, I'm not sure where I can read about it... If I'm guessing, would it be something like this..? MY_controller.php in libraries Code: class MY_Controller extends Controller normal_controller.php in the directory controllers Code: class Normal_controller extends MY_Controller Did some edit.
[eluser]Dam1an[/eluser]
Yeah, spot on If you need a constructor in the other controllers (for any page specific stuff), remember to call the parent as well
[eluser]überfuzz[/eluser]
Thanx!!! I just found a page in the users guide that explains how it's done. Even the part I didn't know; //??? Creating Core System Classes
[eluser]überfuzz[/eluser]
I'm not getting it right, I thought I had the method. When I try to use the MY-controller I get this error message: Quote:Fatal error: Call to undefined method MY_Controller::my_controller() in /home/minister/public_html/application/controllers/test.php on line 7 test.php in controllers folder Code: class Test extends MY_Controller { MY_Controller.php Code: class MY_Controller extends Controller
[eluser]Dam1an[/eluser]
Its because in MY_Controller you use the __construct notation, and in Test, you call the parent using MY_Controller() You need to either use __construct or the class name in both cases
[eluser]Dam1an[/eluser]
Test Code: class Test extends MY_Controller { MY_Controller Code: class MY_Controller extends Controller That should fix it
[eluser]überfuzz[/eluser]
Oh I got it running with this: Code: class Test extends MY_Controller { Code: class MY_Controller extends Controller Seems I'm getting all the data through to the view file as well. |
Welcome Guest, Not a member yet? Register Sign In |