Keyslinger
Keyslinger

Reputation: 5274

How do I load CodeIgniter helpers in every page?

I have a view, header.php, that gets loaded in various controller methods. It contains my opening html tag, a base tag for my relative links, and some meta tags that I call in every page of my application. Is there way to load the helpers that render the meta tags and base url so that they are available to header.php every time it is loaded without having to include $this->load->helper('html'); and $this->load->helper('url'); every time I $this->load->view('templates/header', $data); in a controller to load header.php?

Upvotes: 5

Views: 16784

Answers (2)

swatkins
swatkins

Reputation: 13630

If you're needing these that often, you should just add those to your helpers autoload:

In /application/config/autoload.php around line 93, change

$autoload['helper'] = array();

to

$autoload['helper'] = array('html', 'url');

Then, they're loaded on every request.

Upvotes: 18

Cyclone
Cyclone

Reputation: 18295

Simple, add them to the autoload file. That way they'll be accessible from any file, and you won't ever have to call those.

Upvotes: 0

Related Questions