CodeIgniter Forums
Autoloading Libraries - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Autoloading Libraries (/showthread.php?tid=8882)

Autoloading Libraries - El Forum - 06-04-2008

Hi,I've got a library called Layout and I'm trying to load it from autoload.php
then from the controller main.php I'm trying to use this library that should be automatically loaded, but it isn't it just shows this error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Main::$layout

Filename: controllers/main.php

Line Number: 10

Fatal error: Call to a member function view() on a non-object in /var/www/system/application/controllers/main.php on line 10

autoload.php :
$autoload['libraries'] = array('database','session', 'layout');

class Main extends Controller {

    function __construct(){
        //$this->load->library('layout'); - if I uncomment this and remove from autoload.php it works otherwise it doesn't
    function index(){

application/libraries/Layout.php :

class Layout {
    private $obj;

    public function __construct(){
        $this->obj = & get_instance();
     *  Loads a main template and replaces the content var inside it with $template
     * @param $template String
     * @param $data Array[optional]
     * @param $return Boolean[optional]
     * @param $baseView String[optional]
     * @return String
    public function view($template, $data = array(), $return = false ,  $baseView = "main") {
        return $this->obj->load->view($baseView, array("content" => $this->obj->load->view($template, $data, true)), $return);

CI Version: 1.6.2