include function used before CodeIgniter class changes the view loading order

◇◆丶佛笑我妖孽 提交于 2019-12-24 22:50:25

问题


Ok, so my code looks like this:

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

require_once("/application/controllers/base/genericPageC.php");

class TutorialsC extends GenericPageC {
    function __construct() {
        parent::__construct();
    }

    protected function loadPage($args) {
        // ...
    }
}

/* End of file tutorialsC.php */
/* Location: ./application/controllers/pages/tutorialsC.php */

The require_once statement is present so I can have my inheritance. Now, when I didn't have the require_once statement and all my code was in a single, mammoth, badly formatted controller, everything worked fine. As soon as I added the require_once, though, my header.php view, in which I have all the scripts and CSS added, is loaded inside the <body> tag, instead of the <head> tag. That causes minor, but annoying, effects on my site's styles. From what I could figure out by myself, I think the order in which the views are loaded is being changed. Any ideas how to fix it?

Update:

Still do not know what caused the problem, but here's what i've done: I went to ./system/core/CodeIgniter.php and i changed the following line:

include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');

to:

ob_start();
include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');
ob_end_clean();

Now it loads as it should.


回答1:


If you need to create methods that are to be used across multiple controllers I think what you'll want to do is create a library rather than trying to require or include your other controller.



来源:https://stackoverflow.com/questions/11349900/include-function-used-before-codeigniter-class-changes-the-view-loading-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!