不能从同一个类的相同方法调用相同的静态方法

kis*_*rgy 6 php error-handling controller codeigniter

我的Codeigniter 2.1.0应用程序中有这个错误控制器:

<?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);
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

主控制器_menu:

<?php
class Main extends CI_Controller
{
    // ...  a lot of methods here ...
    public static function _menu()
    {
            static $menuItems = array( //just a simple array
                                     );
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

facebook()方法与index()完全相同,但索引工作正常,facebook()抛出此消息:

Fatal error: Class 'Main' not found in /var/www/MYApplicationName/application/controllers/error.php on line 22
Run Code Online (Sandbox Code Playgroud)

地球是如何可能的?我怎么Main::_menu()能从facebook()方法到达?

kis*_*rgy 1

根据@TheShiftExchange 的回答,我能够追踪到路由设置导致了这种行为。我的config/routes.php看起来像这样:

$route['404_override'] = 'error/index';
$route['(:any)'] = "main/$1";
Run Code Online (Sandbox Code Playgroud)

www.example.com/nonexistent-url所以,当我向控制器发出请求时main,CI 注意到没有这样的方法,所以它error/index也运行了,但main那时控制器已经加载了。

另一种方法facebook是从 only 的现有方法重定向的main,例如gallery,这样就像我转到 url 一样www.example.com/error/facebook,因此main控制器不会加载,因为只error/facebook请求了。如果我调用www.example.com/error/index它,效果是一样的,因为在这种情况下,main控制器未加载,仅加载error.

(赏金发放给@TheShiftExchange,因为他的答案是最准确的,并为我提供了能够追踪问题的最佳信息。谢谢!
我的重定向之一从未到达,我认为正在调用错误/索引页面。)