打开所需文件失败

时间:2015-12-30 17:54:55

标签: php

我正在尝试从控制器内部写入控制台:

with open(mywebpage, 'r+') as f:
     text = f.read ()
     text = re.sub("            $url = 'www.youtube.com.*","            $url ='www.youtube.com{};".format(newyoutubelink), text)
     f.seek(0)
     f.write(text)

我收到此错误:

private function _getHintsFromList($list, $curated = false) {
    set_include_path(dirname(dirname(__FILE__)).'/lib'.PATH_SEPARATOR.get_include_path());
    require('../../FirePHPCore/FirePHP.class.php');
    $firephp = FirePHP::getInstance(true);
    $firephp->fb('Hello World');
}

我已经多次检查过,FirePHPCore文件夹是控制器所在的2个文件夹:

enter image description here

我做错了什么以及如何解决?

2 个答案:

答案 0 :(得分:0)

通常,您必须在autoloading文件中指定包含的文件。 ... set_include_path(get_include_path().PATH_SEPARATOR.'app/'); function __autoload($class){ // autoloader require_once($class.'.php'); } ... 函数的实际情况也是如此:
的index.php:

class HintController{
    ...
    private function _getHintsFromList($list, $curated = false) {

        $firephp = \FirePHP::getInstance(true);
        $firephp->fb('Hello World');
    }
    ...
}

然后你可以像下面那样调用你的函数:

{{1}}

答案 1 :(得分:0)

在这种情况下,

set_include_path()无效。必须考虑执行上下文(CLI,HTTP服务器等) 更简单,更简单,更容易出错,只需做这样的事情:

$path = dirname(dirname(__FILE__)); 
require $path . '/../../FirePHPCore/FirePHP.class.php'; 

它适用于您的情况。稍后,您可以考虑查看autoload方法和相关问题,例如PSR-4 / PSR-0