我的 Codeigniter 2.1.0 应用程序中有这个错误 Controller :
<?php
class Error extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
set_status_header(404);
$data->menuItems = Main::_menu();
$data->title = "404 error !";
$data->pageview = 'templates/404';
$this->load->view('templates/main', $data);
}
public function facebook()
{
set_status_header(404);
$data->menuItems = Main::_menu();
$data->title = "Facebook error !";
$data->pageview = "templates/facebook_error";
$this->load->view('templates/main', $data);
}
}
?>
主 Controller _菜单:
<?php
class Main extends CI_Controller
{
// ... a lot of methods here ...
public static function _menu()
{
static $menuItems = array( //just a simple array
);
}
}
?>
facebook() 方法与 index() 完全相同,但索引工作正常,facebook() 抛出此消息:
Fatal error: Class 'Main' not found in /var/www/MYApplicationName/application/controllers/error.php on line 22
地球怎么可能?如何从 facebook() 方法到达 Main::_menu()
?
最佳答案
从另一个 Controller 调用函数会破坏 MVC,并将您置于 HMVC 领域。
请看this thread ,还有 CodeIgniter 的 Modular Extensions (HMVC) Plugin如果您真的需要这样做。
关于php - 无法从同一类的相同方法调用相同的静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11967450/