hooks CodeIgniter

umaxim
umaxim used Ask the Experts™
on
Hi i create a hook file with mysql query in CodeIgniter  so it take some information like configuration from there like name of the website some staff. How i can send this data to controllers so i can use it in future for example to put on template or just to give some access to some controller.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
You might try putting the information into the $_SESSION array.  That is how most data is carried from request to request.

Author

Commented:
no hook run before controller so i need just to save it in some global variable.
Most Valuable Expert 2011
Top Expert 2016
Commented:
$_SESSION is a global variable.  So is $GLOBALS but it does not have the ability to persist between requests.
http://www.php.net/manual/en/session.examples.basic.php
http://www.php.net/manual/en/language.variables.scope.php

Author

Commented:
You did not understand i did not change page i just load hook before all different controller load. So i load it and then controller load. But i want to load in hook my configuration in some array so i can use it latter when begin controller load. It the same page. I did not need to change page and save it for next page.
@Ray,
$_SESSION does not work as expected in CI as CI has its own session class, that will pull all data out of the $_SESSION array see -> http://codeigniter.com/user_guide/libraries/sessions.html So while your solution is the way I would do it, its done a little differently in CI, using $this->session->set_userdata as mentioned in the link I posted.

@umaxim he was giving you a proper solution, you are asking "How can I set this, so that I can later access it" which is exactly what sessions are for! Please see the CI manual for how to do this with CI. The manual is your friend and CI is extremely well documented.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial