1

For some reason when I call $this->load->model('whatever') in my controller, the page renders the source code for that model. This is my controller:

<?php
class Testing extends CI_Controller {

    function index()
    {
        $this->load->model('Testing');
        $this->load->view('testing/view');
    }

}
?>

If I leave out the model loading and load the view as normal, it works fine, but when i load the model the view is not rendered and the model source is.

Also, I tried adding a hook by putting

$hook['pre_controller'] = array(
'class'    => 'Loader',
'function' => 'template',
'filename' => 'ViewTemplate.php',
'filepath' => 'hooks'
);

in my hooks.php and then

Class Loader{

    function template($viewName, $data) {
        $this->view('header');
        $this->view($viewName, $data);
        $this->view('footer');
    }

}

in the "hooks/ViewTemplate.php" file. The goal is to use the template function in controllers instead of view, which will automatically insert a header and footer. Hooks are enabled in config.php. Whenever I add that section to hooks.php, the only output i'm getting when I load a view is the hook source.

Did I try to implement this wrong? Could I have messed up some CI setting? Could it be related to apache or php?

I'm not so worried about whether my hook works, but why I keep getting the source code for files rendered on my page.

2
  • 3
    Make sure that you have a <?php opening tag at the top of your files. Someone else had the same problem earlier today. Commented Mar 20, 2013 at 2:17
  • Glad I said something! I posted this as an answer, an up vote would be appreciated. Thank you. Commented Mar 20, 2013 at 10:37

1 Answer 1

2

Make sure that you have a <?php opening tag at the top of your files. This is a common oversight with CodeIgniter files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.