为什么我不能在 Codeigniter.2.2.1 上从我的控制器扩展控制器?
Why I can't exstends controller from My controller on Codeigniter.2.2.1?
我想创建一些控制器并从 library 调用它并且库将从 Core 扩展
这是
我的控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Page extends Frontend_Controller {
public function __construct() {
parent::__construct();
}
public function index()
{
$this->load->view('main/main_index');
}
}
?>
这是图书馆里的Frontend_Controller
class Frontend_Controller extends MY_Controller{
public function __construct() {
parent::__construct();
}
}
这里是核心MY_Controller
class MY_Controller extends CI_Controller{
public function __construct() {
parent::__construct();
}
}
但是我遇到了这个错误
Fatal error: Class 'MY_Controllers' not found in D:\My data\project\wamp\www\Ecom\application\controllers\page.php on line 3
这是 Codeigniter2.2.1
中的错误
注意:它在 Codeigniter2.2.0
上运行完美
Frontend_Controller 不应该是图书馆。您需要将其与 my_controller 一起放入应用程序的核心文件夹中,然后将自动加载器添加到 my_controller.
将此自动加载器添加到 my_controller.php 的末尾:
/**
* -------------------------------------------------------------------
* Native Autoload - by Phil Sturgeon. New Version!
* -------------------------------------------------------------------
*
* Nothing to do with config/autoload.php, this allows PHP autoload to work
* for base controllers.
*/
function __autoload($class)
{
if (strpos($class, 'CI_') !== 0)
{
if (file_exists($file = APPPATH . 'core/' . $class . EXT))
{
include_once $file;
}
}
}
/* End of file MY_Controller.php */
/* Location: ./application/core/MY_Controller.php */
我想创建一些控制器并从 library 调用它并且库将从 Core 扩展 这是 我的控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Page extends Frontend_Controller {
public function __construct() {
parent::__construct();
}
public function index()
{
$this->load->view('main/main_index');
}
}
?>
这是图书馆里的Frontend_Controller
class Frontend_Controller extends MY_Controller{
public function __construct() {
parent::__construct();
}
}
这里是核心MY_Controller
class MY_Controller extends CI_Controller{
public function __construct() {
parent::__construct();
}
}
但是我遇到了这个错误
Fatal error: Class 'MY_Controllers' not found in D:\My data\project\wamp\www\Ecom\application\controllers\page.php on line 3
这是 Codeigniter2.2.1
中的错误
注意:它在 Codeigniter2.2.0
Frontend_Controller 不应该是图书馆。您需要将其与 my_controller 一起放入应用程序的核心文件夹中,然后将自动加载器添加到 my_controller.
将此自动加载器添加到 my_controller.php 的末尾:
/**
* -------------------------------------------------------------------
* Native Autoload - by Phil Sturgeon. New Version!
* -------------------------------------------------------------------
*
* Nothing to do with config/autoload.php, this allows PHP autoload to work
* for base controllers.
*/
function __autoload($class)
{
if (strpos($class, 'CI_') !== 0)
{
if (file_exists($file = APPPATH . 'core/' . $class . EXT))
{
include_once $file;
}
}
}
/* End of file MY_Controller.php */
/* Location: ./application/core/MY_Controller.php */