带有 load() 和视图的错误代码点火器


error codeigniter with load() and views

下午好,

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

我找到的解决方案是执行此操作<=>

(1) 在当地

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

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

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

我不知道为什么我必须dis这个?如果有人知道为什么你能解释我。

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

识别问题

我已经在 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.

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

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