Welcome Guest, Not a member yet? Register   Sign In
Autoload libraries fail when extending Controller
#1

[eluser]Hyra[/eluser]
So,

I have integrated the smarty template engine within the CI framework.
This was done by creating a library "smarty_library" which invokes the Smarty class and such.

smarty_library has been added to the config/autoload.php file and this all works fine.

But! now I'm trying to extend the controller, and things go wrong Smile

In the /libraries folder I've created a file "MY_Controller.php":

Code:
class MY_Controller extends Controller {
    
    function __construct() {
        parent::Controller();
    }
    
};

and on my home.php controller I did:

Code:
class Home extends MY_Controller {

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

    function index() {
        $this->smarty_library->assign("PageTitle", "Test");
        $this->smarty_library->view("home.html");
    }

};

Now, when doing this things break .. i get the error message:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Home::$smarty_library

Filename: controllers/home.php

Line Number: 15

Fatal error: Call to a member function assign() on a non-object in /long/path/to/controllers/home.php on line 15

When i don't extend it on MY_Controller but use the normal Controller everthing works fine again.

I can't for the life of me figure out why it wouldn't recognise the autoloaded library when using the extended controller.

Any suggestions?
#2

[eluser]Hyra[/eluser]
Even when i add:

Code:
$this->load->library("smarty_library", "smarty_library");
$this->smarty_library->assign("PageTitle", "TEST");

in the home.php controller the error remains




Theme © iAndrew 2016 - Forum software by © MyBB