本文介绍了CodeIgniter类更改视图加载顺序之前使用的include函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我的代码如下:

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 */

存在 require_once 语句,因此我可以继承我的继承.现在,当我没有 require_once 语句,而我所有的代码都在一个庞大的,格式错误的控制器中时,一切正常.但是,一旦我添加了 require_once ,我的 header.php 视图(其中已经添加了所有脚本和CSS)就被加载到<中.body> 标记,而不是< head> 标记.这会对我的网站样式造成轻微但令人讨厌的影响.从我自己能弄清楚的角度来看,我认为加载视图的顺序正在改变.有任何解决方法的想法吗?

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?

更新:

仍然不知道是什么引起了问题,但这是我所做的:我去了./system/core/CodeIgniter.php,我更改了以下行:

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');

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

收件人:

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

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

现在它会按原样加载.

推荐答案

如果您需要创建要在多个控制器之间使用的方法,我想您要做的就是创建一个,而不是尝试要求或包括其他控制器.

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.

这篇关于CodeIgniter类更改视图加载顺序之前使用的include函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 21:51