0
votes

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
You requires could possibly be outputting something or including whitespace, which is throwing it into your HTML doc. It is recommended that you do your requires before writing your HTML doc. You should not be doing any processing within your views. - Steven Lu
the issue that the require throws white spaces is present... twice, for some reason. but i do not see why the script tags are written in the body tag, how the white spaces are causing this... as for doing requires before the html doc writing, well, i dunno how the codeigniter works exactly, but the loadPage method of my controller should start writing the document AFTER the inherited class is included, shouldn't it? logically?... - Mihai Mircea Ionescu
I had a tough time interpreting your comment. If you're loading you are loading the view with requires in it, it'll stream it to the client, processing the requires only when the statement gets hit by the stream, therefore causing your whitespace issues. - Steven Lu
i have no requires/includes in any view. - Mihai Mircea Ionescu

1 Answers

0
votes

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.