CodeIgniter Forums
Error When Loading View in My_Controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Error When Loading View in My_Controller (/thread-45756.html)



Error When Loading View in My_Controller - El Forum - 10-04-2011

[eluser]Dr. Seuss[/eluser]
I have been trying to implement the solution referenced at:

http://stackoverflow.com/questions/4708639/error-when-trying-to-load-view-in-my-controller
...and...
http://ellislab.com/forums/viewthread/162002/

Don't know why, but Aptana indicates a syntax error on my line:

Code:
parent::load->view('common/header_out');

...which is seconded by the interpreter when I execute: "unexpected T_OBJECT_OPERATOR"

Previously I tried using:

Code:
$this->load->view('common/header_out');

...which generated the following errors:

Quote:Warning: include(application/errors/error_php.php) [function.include]: failed to open stream: No such file or >directory in /home/uom2/www/system/core/Exceptions.php on line 167

Warning: include() [function.include]: Failed opening 'application/errors/error_php.php' for inclusion >(include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/uom2/www/system/core/Exceptions.php on >line 167

Further, I tried using:

Code:
$CI =& get_instance();
$CI->load->view('common/header_out');

...which generates precisely the same results as above!

Quote:Warning: include(application/errors/error_php.php) [function.include]: failed to open stream: No such file or directory in /home/uom2/www/system/core/Exceptions.php on line 167

Warning: include() [function.include]: Failed opening 'application/errors/error_php.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/uom2/www/system/core/Exceptions.php on line 167

I am using CI 2.0.

Any help would be appreciated.

application/core/Uom_Controller.php

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

class Uom_Controller  extends CI_Controller
{

public   $data = array();  // Array to store data - passed to views.
public  $view_path = null;  

    public function __construct()
    {
        parent::__construct();

    }

    protected function check_session()
    {
        //Here goes your function
    }

protected function render() {


$data['page_title'] = 'Your title';
data['page_title'] = 'Your title';

      parent::load->view('common/header_out');
      parent::load->->view('home/home', $data);
      parent::load->->view('common/foot');

echo "view rendered:  ".date('Y-m-d H:i:s');



}

}

controllers/home/home.php

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

class Home   extends Uom_Controller  {

    function __construct()
    {
        parent::__construct();

      // Set the view path manually for this method.
      $this->view_path = 'home/home.php';

    }


    function __destruct() {
        $this->render();
    }


    public function index()
    {
        echo "home updated";

    }


    public function out()
    {
        echo "logout";
        echo "<br>";
        echo $this->view_path;
        echo "<br>";

    }


}

obviously the intention is similar to the SO post at the top of this post: I want the
$this->render();
...to be called and render my page header, body, and footer.

(My next task is to add the authentication check to this MY_Controller pattern, so I am hoping that whatever solution works for calling views also works on models.

Thanks everyone and I really have spent hours trying to find a solution to this before once again turning to this forum.