Jump to content

Archived

This topic is now archived and is closed to further replies.

c_pattle

Codeigniter Library problem

Recommended Posts

I have a problem where in a controller constructor I can load the codeigniter libraries such as session and cart but I can never load any libraries that I've written.  Everytime I do it says that it is undefined.  Does anyone know what might be causing this?  Thanks

Share this post


Link to post
Share on other sites

Hmmm. let me get my crystal ball out....

Share this post


Link to post
Share on other sites

Sorry.  So for example if I do

 

class Homepage extends CI_Controller
{
    
    function Homepage()
    {
        parent::__construct();
        
        $this->load->library('layout');
    }
}

 

The library doesn't seem to load because I can't access any of the method in that libary.  But if I was to load the library in another function that wasn't the contoller it works fine

Share this post


Link to post
Share on other sites

$this->load->library('layout');
if (!isset($this->layout)) $this->layout = get_instance()->load->library('layout');
var_dump($this->layout);

 

What does this tell you?

Share this post


Link to post
Share on other sites
class Homepage extends CI_Controller {
    
    public function __construct()
    {
        parent::__construct();
        
        // Assuming layout.php or Layout.php  is located in /application/libraries/
        $this->load->library('layout');
    }

    public function index()
    {
          $whatever = $this->layout->some_method();
    }
}

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.