我部署了一个应用程序,但遇到了问题。这是我的 Controller :
class Account extends CI_Controller {
function test() {
echo "hello";
$this->load->view('account/test');
echo "hello again";
}
输出显示hellohelloagain
。
未调用load->view()
方法。所有 Controller 都会发生这种情况。
开发环境不存在该问题。
我已经:
- 已移除 Hook
- 已检查权限
我的 Apache 日志中没有警告或错误。
更新
我刚刚发现了一些奇怪的事情:
function index() {
$this->load->view('welcome/index'); // NOTHING
$output = $this->load->view('welcome/index', array(), true);
echo $output; // WORKS FINE
}
最佳答案
class Account extends CI_Controller
{
function test() {
echo "hello";// No 01
$this->load->view('account/test'); //No 02
echo "hello again"; //No 03
}
在No 01中,它将显示您提到的hello
字样。然后再次加载 No 02 中的 View (此 View 是空白页面,否则您会收到错误页面未找到)。
错误是:
An Error Was Encountered
Unable to load the requested file: account/test.php
因此您的测试 View 是空页面。然后在No 03中,您将再次传递hello
。所以这也会出现在您的 View 中。
所以你的最终输出是hellohello Again
。
So Finely,这意味着您的代码运行良好。
测试您的 View 是否有效
在你的 View (test.php)中写下这一行并查看输出
<h1>Hi, I'm here</h1>
阅读本文以获取更多知识
关于CodeIgniter 未按预期加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30857387/