需要一次在 Kohana v3.3.1 中生成错误


Require Once Generates Errors in Kohana v3.3.1

如何在控制器(我放入kohana'vendor'twitter-api-php的第三方类)中require_once?我尝试了这个类似的答案,但我不断收到错误(见下文)。我的项目文件结构如下:

kohana
- application
- modules
- system
- vendor

我不断收到这些错误

 Warning: Uncaught exception 'ErrorException' with message 'require_once(C:'wamp'www'kohana): failed to open stream: Permission denied' in C:'wamp'www'kohana'application'classes'Controller'Twitter.php:8 Stack trace: #0 C:'wamp'www'kohana'application'classes'Controller'Twitter.php(8): Kohana_Core::error_handler(2, 'require_once(C:...', 'C:'wamp'www'koh...', 8, Array) #1 C:'wamp'www'kohana'application'classes'Controller'Twitter.php(8): Controller_Twitter::before() #2 C:'wamp'www'kohana'system'classes'Kohana'Controller.php(69): Controller_Twitter->before() #3 [internal function]: Kohana_Controller->execute() #4 C:'wamp'www'kohana'system'classes'Kohana'Request'Client'Internal.php(97): ReflectionMethod->invoke(Object(Controller_Twitter)) #5 C:'wamp'www'kohana'system'classes'Kohana'Request'Client.php(114): Kohana_Request_Client_Internal->execute_request(Object(Request), Object(Response)) #6 C:'wamp'www'kohana'system'classes'Kohana'Request.php(986): Kohana_Request_Client->execute(Object(Request)) #7 C:'wamp'www'kohana'index.p in C:'wamp'www'kohana'application'classes'Controller'Twitter.php on line 8

和这个错误

Fatal error: Controller_Twitter::before(): Failed opening required '' (include_path='.;C:'php'pear') in C:'wamp'www'kohana'application'classes'Controller'Twitter.php on line 8

这是我的代码

<?php defined('SYSPATH') or die ('No direct script access.');
class Controller_Twitter extends Controller {
    public function before()
    {
        // require_once(APPPATH.'vendor/twitter-api-php/TwitterAPIExchange.php');
        require_once Kohana::find_file('vendor/twitter-api-php', 'TwitterAPIExchange');
    }
    public function action_index()
    {
        $view = new View('twitter/index');
        $this->response->body($view);
    }
}

vendor文件夹放在application文件夹中。

applicationmodulessystem文件夹的位置可以用index.php设置,并将存储在APPPATHMODPATHSYSPATH常量中。Kohana::find_files() 将在 APPPATH 中查看,然后在 MODPATH 下的所有加载模块中查找(好的,模块可以位于任何地方,但我假设它们在您的情况下都处于MODPATH之下),最后SYSPATH .Kohana::find_files() 不会神奇地出现在其他任何地方。

另外,为什么不把require_once放在类防御之外呢?喜欢这个。

<?php defined('SYSPATH') or die ('No direct script access.');
// require_once(APPPATH.'vendor/twitter-api-php/TwitterAPIExchange.php');
require_once Kohana::find_file('vendor/twitter-api-php', 'TwitterAPIExchange');
class Controller_Twitter extends Controller {
    public function action_index()
    {
        $view = new View('twitter/index');
        $this->response->body($view);
    }
}