CodeIgniter Forums
how do you load a library for all pages in a 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: how do you load a library for all pages in a controller? (/thread-52022.html)



how do you load a library for all pages in a controller? - El Forum - 05-26-2012

[eluser]Abel A.[/eluser]
Lets say I want to load a library in all my pages, how would I do that instead of calling it on each function?

Example:
Code:
class login extends CI_Controller {

public function index()
{
  $this->load->helper('url');
}

public function forgot()
{
  $this->load->helper('url');

}

public function activate()
{
  $this->load->helper('url');
}

}



how do you load a library for all pages in a controller? - El Forum - 05-27-2012

[eluser]Aken[/eluser]
Do it in the constructor - __construct()


how do you load a library for all pages in a controller? - El Forum - 05-27-2012

[eluser]InsiteFX[/eluser]
As for the url_helper I would autoload it being as it is always being used!

Else do like Aken says.




how do you load a library for all pages in a controller? - El Forum - 05-27-2012

[eluser]Abel A.[/eluser]
Yeah, thanks guys. I just found the autoload feature in CI Smile