Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I have anything that I need on all pages I do the following.</p> <ol> <li>Add a <a href="http://codeigniter.com/user_guide/general/helpers.html" rel="nofollow">helper</a>.</li> <li>Add your new helper to <a href="http://codeigniter.com/user_guide/general/autoloader.html" rel="nofollow">autoload</a>.</li> <li>Simply call your function where ever you need to.</li> </ol> <p>The reason I do this, is the because if you need it on many different controllers then having it in one easily accessible place is very handy. When you need to maintain your code it will make it a lot easier too. For example, if you want to add in caching then you can just add that code into that single function instead of having to change it in every controller.</p> <p>Infact, in your specific case, I actually <a href="http://codeigniter.com/user_guide/general/creating_libraries.html" rel="nofollow">created my own session class</a> to extend the CI Session. As a very basic example (I also use <a href="http://codeigniter.com/user_guide/libraries/sessions.html" rel="nofollow">sessions in database</a> for this):</p> <pre><code>class MY_Session extends CI_Session { public function __construct() { parent::__construct(); } public function login($email, $password) { $CI =&amp; get_instance(); $CI-&gt;load-&gt;model('usermodel', 'user'); $result = $CI-&gt;user-&gt;login($email, $password); if($result === false) { return false; } else { $this-&gt;set_userdata('email', $result-&gt;email); return true; } } public function is_logged_in() { $email = $this-&gt;userdata('email'); if(!empty($email)) { return true; } else { return false; } } } </code></pre> <p>This way, since you are probably storing this information in sessions, it makes a lot of sense to keep that information together.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload