CodeIgniter扩展控制器以将内容插入基本视图生成没有错误的空白页

时间:2014-08-12 16:25:51

标签: php codeigniter

使用2011年Best Way to Structure Partial Views

上的stackoverflow答案

我已经构建了一个带侧边栏,导航和内容区域的仪表板基本视图,应该在CI _output()上插入内容,类似于下面的代码示例。当我单独运行$ this-> load-> view('dashboard / base')时,我得到了仪表板,但在使用_output()实现MY_Controller后,它显示数据正确进入,但仪表板/基座视图永远不会显示相反,我得到一个空白页面,空的HTML标记,没有错误可以遵循。为了清楚起见,如果我从MY_Controller _output()获取代码并将其放入我的Dashboard控制器中,它可以正常工作。所以这不是视图,它可以与所有的子视图等一起工作。

好的,没有错误可以检查php.ini

  1. error_reporting设置为E_ALL
  2. display_error设置为On
  3. 好的,我们可以检查类似命名的类和/或视图吗?刮掉所有东西只有:

    • 1个控制器(仪表板),
    • 1个型号(Dashboard_model)和
    • 用于简单构建仪表板的15个视图
      • 具有相似命名视图(页眉和页脚)的2个视图,但它们由文件夹结构分隔,并且都未被使用

    ...所以没有类别或观点发生冲突

    好的,让我们检查一下stackoverflow问题/答案:

    1. 确保MY_Controller通过source进入应用程序/核心...确定
    2. 尝试设置ini_set('display_errors',1);通过source ...没有显示错误
    3. 尝试启用CI登录并通过source将其设置为4,日志中没有错误
    4. 记录了这个:

      DEBUG - 2014-08-12 09:04:09 --> Config Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Hooks Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Utf8 Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> UTF-8 Support Enabled
      DEBUG - 2014-08-12 09:04:09 --> URI Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Router Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Output Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Security Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Input Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> XSS Filtering completed
      DEBUG - 2014-08-12 09:04:09 --> XSS Filtering completed
      DEBUG - 2014-08-12 09:04:09 --> CRSF cookie Set
      DEBUG - 2014-08-12 09:04:09 --> Global POST and COOKIE data sanitized
      DEBUG - 2014-08-12 09:04:09 --> Language Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Loader Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Controller Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Session Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Helper loaded: string_helper
      DEBUG - 2014-08-12 09:04:09 --> Encrypt Class Initialized
      DEBUG - 2014-08-12 09:04:09 --> Database Driver Class Initialized
      ERROR - 2014-08-12 09:04:09 --> Severity: 8192  --> mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead D:\htdocs\example\app\codeigniter\system\database\drivers\mysql\mysql_driver.php 91
      DEBUG - 2014-08-12 09:04:09 --> Session routines successfully run
      DEBUG - 2014-08-12 09:04:09 --> Helper loaded: security_helper
      DEBUG - 2014-08-12 09:04:09 --> Helper loaded: url_helper
      DEBUG - 2014-08-12 09:04:09 --> Helper loaded: utility_helper
      DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/content/reporting.php
      DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/header.php
      DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/sidebar.php
      DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/topnav_left.php
      DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/topnav_right.php
      DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/footer.php
      DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/base.php
      DEBUG - 2014-08-12 09:04:09 --> Final output sent to browser
      DEBUG - 2014-08-12 09:04:09 --> Total execution time: 0.0512
      

      好的,所以确实没有错误...但我还有一个空白页?这是我的代码示例,以防它对我以外的其他人更有用,现在我觉得已经踩到了,有点苦,我无法弄明白:

      Class Dashboard extends MY_Controller
      {
          function __construct() {
              parent::__construct();   
          }
      
          public function index() {
              $this->load->view('dashboard/content/reports'); // only have "Hello World!" stub in view
          }
      }
      
      Class MY_Controller extends CI_Controller
      {
          var $page_title = 'my page title';
          var $page_keywords = 'my keywords';
          var $page_description = 'my description';
          var $dashboard_title = 'my dashboard title';
      
          function __construct() {
              parent::__construct();
              $this->load->model('dashboard_model');
              $this->load->library('session');
              $this->load->helper('security');
              $this->load->helper('url');
              $this->load->helper('utility');
          }
      
          public function _output($content) {
      
              $data = array(
                  'page_title' => $this->page_title,
                  'page_keywords' => $this->page_keywords,
                  'page_description' => $this->page_description,
                  'dashboard_title' => $this->dashboard_title,
                  'content' => &$content
              );
      
              print_r("<pre>");
              print_r($data);
              print_r("</pre>");
      
              $this->load->view('dashboard/base', $data);
          } // END public function _output
      }
      

      任何人都知道发生了什么事?

      顺便说一下,为什么在我为此解决方案引用的示例中通过引用传递$ content?

1 个答案:

答案 0 :(得分:0)

如果您在课堂上使用_output(),它不会将您的数据回显到屏幕上,您需要自己动手操作,并且需要视图返回数据供您回显,因此请查看需要使用它的第三个参数。所以在你的班级中,最后一行输出应该是:

echo( $this->load->view('dashboard/base', $data, TRUE) );