模型直接输出代码

时间:2011-12-27 22:15:33

标签: php codeigniter

每当我尝试在CodeIgniter中加载模型时,它会将该模型文件的内容输出到Web浏览器。以下是我当前设置的一些示例。

文件名:test.php

class test extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }

    function get_test_data() {
        return 'test data';
    }
}

文件名:home.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

    public function index()
    {
        $this->load->view('header');
        $this->load->view('nav');
        $this->load->view('dyn_content');

        $this->load->model('Test');
        $data['query'] = $this->Blog->get_test_data();

        $this->load->view('footer');

    }
}

加载页面的日志

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

DEBUG - 2011-12-27 15:43:56 --> Config Class Initialized
DEBUG - 2011-12-27 15:43:56 --> Hooks Class Initialized
DEBUG - 2011-12-27 15:43:56 --> Utf8 Class Initialized
DEBUG - 2011-12-27 15:43:56 --> UTF-8 Support Enabled
DEBUG - 2011-12-27 15:43:56 --> URI Class Initialized
DEBUG - 2011-12-27 15:43:56 --> Router Class Initialized
DEBUG - 2011-12-27 15:43:56 --> No URI present. Default controller set.
DEBUG - 2011-12-27 15:43:56 --> Output Class Initialized
DEBUG - 2011-12-27 15:43:56 --> Security Class Initialized
DEBUG - 2011-12-27 15:43:56 --> Input Class Initialized
DEBUG - 2011-12-27 15:43:56 --> Global POST and COOKIE data sanitized
DEBUG - 2011-12-27 15:43:56 --> Language Class Initialized
DEBUG - 2011-12-27 15:43:56 --> Loader Class Initialized
DEBUG - 2011-12-27 15:43:56 --> Database Driver Class Initialized
DEBUG - 2011-12-27 15:43:56 --> Controller Class Initialized
DEBUG - 2011-12-27 15:43:56 --> File loaded: application/views/header.php
DEBUG - 2011-12-27 15:43:56 --> File loaded: application/views/nav.php
DEBUG - 2011-12-27 15:43:56 --> File loaded: application/views/dyn_content.php
DEBUG - 2011-12-27 15:43:56 --> Model Class Initialized

正如您所见,它在加载模型后停止。当我注释掉加载模型的行(或者甚至只是将结果分配给$ data [&#39;查询&#39;])时,页面会完美地加载并完全符合我的预期。

任何人都可以看到任何丢失或设置错误的内容吗?

1 个答案:

答案 0 :(得分:0)

根据@DaveRandom评论中提供的建议,我只是停止了<?php标签。我想我还在考虑观点。

谢谢@DaveRandom。