【问题标题】:error codeigniter with load() and views带有 load() 和视图的错误 codeigniter
【发布时间】:2013-10-23 14:24:45
【问题描述】:

下午好,

CodeIgniter 的 load() 方法有问题。 在当地一切都很好。但是当我尝试在在线服务器中检查我的应用程序时,我遇到了问题 无法加载请求的文件:警告/信息

我找到的解决方案是这样做

(1) 在本地

public function test() {
         $this->load->view('warning/info');
    }

(2) 在在线服务器中,我必须像这样指定扩展名

public function test() {
     $this->load->view('warning/info.php');
}

我不知道我为什么要取消这个?如果有人知道为什么请你解释一下。

非常感谢您,很抱歉我的英语不流利,但希望您能理解我的信息。

【问题讨论】:

  • 看到这个:Remove .php extensions with .htaccess。它与服务器配置有关。在 .htaccess 中添加规则将允许您省略 .php 扩展名。顺便说一句,load 不是方法而是属性(Loader 类的实例)

标签: php codeigniter


【解决方案1】:

识别问题

我查看了 system/core/Loader.php 中的 _ci_load() 方法,并提取了似乎导致您出现问题的代码:

#/system/core/Loader.php::_ci_load

$_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
$_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view;

foreach ($this->_ci_view_paths as $view_file => $cascade)
{
        if (file_exists($view_file.$_ci_file))
        {
                $_ci_path = $view_file.$_ci_file;
                $file_exists = TRUE;
                break;
        }

        if ( ! $cascade)
        {
                break;
        }
}

....

if ( ! $file_exists && ! file_exists($_ci_path))
{
        show_error('Unable to load the requested file: '.$_ci_file);
}

解决问题

我查看了使用的方法,它们似乎都支持 PHP 4.0.3 及更高版本,因此您的问题很可能与不兼容的 PHP 版本有关。

似乎触发您的问题的代码在这里:

if ( ! $file_exists && ! file_exists($_ci_path))
{
        show_error('Unable to load the requested file: '.$_ci_file);
}

现在,我的猜测是当你添加 .php 扩展时它会起作用,因为这个方法实际上通过了:

file_exists($_ci_path)

一个可能的操作是查看 $file_exists 变量发生了什么,因为它仅在发生这种情况时设置为 true:

if (file_exists($view_file.$_ci_file))

可能有帮助的其他信息

php.net 上的 file_exists 方法也有一个有趣的评论:

file_exists will have trouble finding your file if the file permissions are not read enabled for 'other' when not owned by your php user. I thought I was having trouble with a directory name having a space in it (/users/andrew/Pictures/iPhoto Library/AlbumData.xml) but the reality was that there weren't read permissions on Pictures, iPhoto Library or AlbumData.xml. Once I fixed that, file_exists worked.

也许您可以发布这些文件的权限或尝试在那里探索。

您也可以尝试在系统类中进行调试,并查看其中是否有任何问题。这很奇怪,因为我自己从来没有遇到过类似的事情,而且老实说,我看不出图书馆会出现什么失误——这很可能与权限有关

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-08
    • 2016-10-24
    • 1970-01-01
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多