Welcome Guest, Not a member yet? Register   Sign In
controller inheritance
#8

[eluser]louis w[/eluser]
Why wouldn't they be able to inherit? Just keep subclassing. Simple example:

Code:
/* Admin.php */

class Admin extends Controller {

    var $say_hi = 'Hello';

    function __construct() {
            parent::__construct();
    }
    
    /* Methods */

}

/* - - - - - - - - - - - - - - - - - - - - - - - */
/* Page.php */

require_once('Admin.php');

class Page extends Admin {

    function __construct() {
            parent::__construct();
    }
    
    /* Methods */

    function test() {
            echo $this->say_hi;
    }


}

When instantiated, the Page controller will have access to methods and variables set inside both Admin and Controller (CI). I often do soemthing like this where Admin would load all the libraries, configs, etc, and then page just loads what it needs.

You can also do this with models. I have one model called CRUD which contains all the db logic methods and then subclass it and add table specific info and have a fully featured crud model with like 4 lines of code.


Messages In This Thread
controller inheritance - by El Forum - 06-30-2008, 11:42 PM
controller inheritance - by El Forum - 07-01-2008, 12:07 AM
controller inheritance - by El Forum - 07-01-2008, 12:47 AM
controller inheritance - by El Forum - 07-01-2008, 04:40 AM
controller inheritance - by El Forum - 07-01-2008, 09:45 AM
controller inheritance - by El Forum - 07-01-2008, 01:19 PM
controller inheritance - by El Forum - 07-01-2008, 01:25 PM
controller inheritance - by El Forum - 07-01-2008, 02:08 PM
controller inheritance - by El Forum - 07-01-2008, 03:17 PM
controller inheritance - by El Forum - 07-02-2008, 02:42 AM
controller inheritance - by El Forum - 07-02-2008, 05:51 AM
controller inheritance - by El Forum - 07-02-2008, 10:20 AM
controller inheritance - by El Forum - 07-02-2008, 11:07 AM
controller inheritance - by El Forum - 12-17-2010, 07:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB