2

I want to extend CI_Controller as a base class for my other classes according do my own need.

I read the user guid. Acted as what it told me.

I created application core:

./application/core/MY_ControllerPermission.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_ControllerPermission extends CI_Controller 
{
    function __construct()
    {
        parent::__construct();
    }
}

And this is my controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if(class_exists('MY_ControllerPermission'))
    echo 'clase does exist';
else
    echo 'clase does not exist';

class Users extends MY_ControllerPermission
{
    ....

In my config file:

$config['subclass_prefix'] = 'MY_';

It just show blank page and "clase does not exist"

So where is the problem?


UPDATE

If I add this line:

include_once(APPPATH . 'core/MY_ControllerPermission.php');

before my controller, it would work. Doesn't CodeIgniter load core PHP files automatically?

4

1 回答 1

2

重命名MY_ControllerPermission.phpMY_Controller.php,你应该很高兴。

您可以将其他所有内容保持不变,如果您不想使用,甚至不需要MY_Controller为您的班级使用名称。

于 2013-07-07T18:10:15.697 回答