Welcome Guest, Not a member yet? Register   Sign In
How do I subclass one of my own controllers? [SOLVED]
#4

[eluser]jwright[/eluser]
[quote author="Jelmer" date="1279839987"]Maybe just like this? (not pretty but probably works)

Code:
<?php

require APPPATH . 'controllers/done.php';

class Todo extends Done
{

    public function __construct()
    {
        parent::__construct();
        echo "Todo constructor<br/>";
    }

    public function index()
    {
        echo "Inside Todo index <br/>";
    }

}

I haven't done this, but I have worked with multiple base controllers. I implemented those by writing an autoloader that would autoload the class after "extends". Thus avoiding needing "require" and it might also be a better solution for you. Write one abstract base controller and then extend both Todo and Done from that base.[/quote]

I like this for a couple reasons.
1. It explicitly shows the file where the base class is located
2. It should work on any CI install even if an autoloader is not setup

That's not to say autoloaders don't have their place. It's nice to not have to worry about these require statements, especially if you would need a lot of them.


Messages In This Thread
How do I subclass one of my own controllers? [SOLVED] - by El Forum - 07-22-2010, 03:46 PM
How do I subclass one of my own controllers? [SOLVED] - by El Forum - 07-22-2010, 04:06 PM
How do I subclass one of my own controllers? [SOLVED] - by El Forum - 07-22-2010, 06:23 PM
How do I subclass one of my own controllers? [SOLVED] - by El Forum - 01-28-2012, 01:33 PM



Theme © iAndrew 2016 - Forum software by © MyBB