• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to know if a model is already loaded?

Hi everyone!

I'm so sorry but I don't found anywhere what I'm looking for to solve my problem (..and sorry for my English.. I'm italian ) Tongue

...that's my problem:
in the constructor of the controller I load a model that I use in the head of the index function:
function index() {
if ( $this->login_model->_is_logged() ) {
  //show logged in page
else {
  //show login form
and it works perfectly... if I don't reload the page shown Big Grin

The "_is_logged()" function checks session and cookies, but these contain a encrypted part of the data passed via form.

When I refresh the "logged in" page, without resending data, it goes back, obviously, at the login form, because it reloads the model again and the saved datas are lost.

How can I know if a model is already loaded or not?

Thanks guys Smile

edit: oh.. I've seen this is not the correct section for my question Sad ..excuse me..


Your login information should be stored in sessions.

Read the CodeIgniter User Guide session library.


You can use the log_message() function and put it in the constructor, so it will be executed when it initiated

Put this in your model's constructor (parent::Model())

log_message ("debug", "Yourmodel is loaded");

don't forget to set the log config to debug mode, see the config.php file

$config['log_threshold'] = 2;

And set the system/logs directory permission to writable (by default CI will create the log files here)

or set the logs directory in another dir
$config['log_path'] = 'another/directory/logs/';

CI will then create the log file in the directory. monitor the log files as you like. You can get the debug message to see if your model is already loaded or not in the log files.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.