0

我试图创建一个 Zend Framework 自定义提供程序,在这里:

    if($module == 'default'){
        $modelsPath = dirname(__FILE__) . '/../application/models';
        $filePath = realpath($modelsPath) . '/' . $name . '.php';
    } else
    if(!$module == ''){
        $modelsPath = dirname(__FILE__) . '/../application/' . $module . '/models';
        $filePath = realpath($modelsPath) . '/' . $name . '.php';
    } else {
        die('Please enter a module!');
    }

当我试图创建文件的路径并且它的默认模块一切正常时,但对于 ex。无论真实路径返回什么,模块都是另一个词?!错误在哪里?

4

3 回答 3

2

尝试使用APPLICATION_PATH 常量。

if($module == 'default'){
        $modelsPath = APPLICATION_PATH . '/models';
        $filePath = realpath($modelsPath) . '/' . $name . '.php';
    } else
    if(!$module == ''){
        $modelsPath = APPLICATION_PATH . '/' . $module . '/models';
        $filePath = realpath($modelsPath) . '/' . $name . '.php';
    } else {
        die('Please enter a module!');
    }
于 2012-05-14T01:26:14.037 回答
0

从php手册中取出:

realpath() 在失败时返回 FALSE,例如如果文件不存在。

笔记:

正在运行的脚本必须对层次结构中的所有目录具有可执行权限,否则 realpath() 将返回 FALSE。

所以问题很可能是文件夹权限或路径错误!

于 2012-05-13T19:38:51.840 回答
0

通过简单的回显 $filePath 来仔细检查路径是否存在。如果这检查没问题,那么请确保“用户”(例如 apache、www-data)具有足够的权限。如果您不确定您的服务器在运行谁,您可以简单地通过回显进行调试whoami

于 2012-05-14T15:02:58.150 回答