Welcome Guest, Not a member yet? Register   Sign In
Extending a controller?
#1

[eluser]mvdg27[/eluser]
Hi guys,

I'm wondering if it is possible to extend a controller? I'm thinking something like this: I have a controller 'website' with a bunch of functionality. Now I would want to have something like 'website_extra', with some extra functionality and some changed functionality, but mainly the same stuff as 'website' .. it doesn't make sense to copy the everything to a new controller, does it?

Is extending a controller possible within the CI framework?

Thanks! Michiel
#2

[eluser]Greg Aker[/eluser]
Yes. http://ellislab.com/codeigniter/user-gui...aries.html
[/url]

Also search the forums for "MY_Controller"

-greg
#3

[eluser]sophistry[/eluser]
are the EE people finally coming up for air? ;-)
#4

[eluser]mvdg27[/eluser]
Hi Greg,

Thanks for your reply! I think the link you gave me applies just to libraries and I don't think that's what I'm after. I would actually want to extend my controller class as one would normally do in PHP.

I've searched the forum for MY_Controller, and found some threads, but still confused about how it works exactly. Could you help me a bit on the way on this one?

How could I use MY_Controller to extend 'website' with 'website_extra'? Can I use this way for different controllers as well (e.g. 'simplenews' and 'advancednews').

Thanks again! -Michiel
#5

[eluser]sophistry[/eluser]
Forget MY_Controller.php - it's for changing the behavior of the Controller Class itself.

You want something like this (normal class extension):

Website.php
Code:
<?php
Class Website extends Controller {

function Website()
    {
        parent::Controller();
    }

}
//EOF

Website_extra.php
Code:
<?php
require_once('Website.php');
Class Website_extra extends Website {

    function Website_extra()
    {
        parent::Website();
    }

}
//EOF
#6

[eluser]mvdg27[/eluser]
Great! That was what I was after!

Thanks, Michiel




Theme © iAndrew 2016 - Forum software by © MyBB