codeigniter: extending common controller

后端 未结 3 2041
长情又很酷
长情又很酷 2021-01-24 21:31

I\'ve read all the post I found regarding this issue but nothing works. I\'m using Codeigniter 2.02 in a LAMP with Apache2.2 and PHP5.3.2

I\'m trying to create a common

3条回答
  •  春和景丽
    2021-01-24 21:52

    Take a look at this post from Phil Sturgeon:

    http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY

    The key is using the native autoload as explained in his post:

    /*
    | -------------------------------------------------------------------
    |  Native Auto-load
    | -------------------------------------------------------------------
    | 
    | Nothing to do with cnfig/autoload.php, this allows PHP autoload to work
    | for base controllers and some third-party libraries.
    |
    */
    function __autoload($class)
    {
        if(strpos($class, 'CI_') !== 0)
        {
            @include_once( APPPATH . 'core/'. $class . EXT );
        }
    }
    

    NOTE

    As a note, you'll want to put all of your "base" controllers in the core folder for CI2+

提交回复
热议问题