Welcome Guest, Not a member yet? Register   Sign In
MY_controller problem
#1

[eluser]Near[/eluser]
Hi! I'm creating a program which allows user to register and log in to a specific page. This is my problem:

1) validates user if registered or not
2) determine if the user is currently logged in

i managed to finish the first issue.
but the second issue. I created a my_controller which extends the ci_controller.
then i declare a global variable called $is_login.. I can set its value to true on one page. But when i load another page. The value of the variable $is_login was set to false.. Am i doing it wrong?do i have to store the variable to session instead of using my_controller? Thanks!
#2

[eluser]Near[/eluser]
here is my_controller
Code:
class base_c extends ci_controller{
protected $is_login;
function __construct(){
parent::__construct();
$this->load->library('auth');
$this->is_login = (bool) $this->auth->is_login();
}
}

welcome controller

Code:
class welcome extends base_c{

function __contruct(){
parent::__construct();
var_dump($this->is_login);
}

}
class auth
Code:
function is_login(){
return true;
}
#3

[eluser]marcogmonteiro[/eluser]
Code:
class base_c extends ci_controller{
      protected $is_login;
      
      function __construct(){
          parent::__construct();
          $this->load->library('auth');
          echo ($this->auth->is_login() = FALSE) ? 'you're are not logged in' :  'you are now logged in';
     }
}

perhaps something like this?
#4

[eluser]CroNiX[/eluser]
If you are going to extend a MY_Controller you will need an autoloader for it to find the class. It also doesn't look like you are extending things properly and/or perhaps don't have the extended base classes in the appropriate directory (/application/core)
http://philsturgeon.co.uk/blog/2010/02/C...ing-it-DRY
#5

[eluser]Near[/eluser]
Yes im able to set the $this->is_login to true if already logged in and false if not. The only problem that i encountered is that, for example im on the home page. The value of $is_login is true but when i click for example activities the value of $is_login is now FALSE..
#6

[eluser]weboap[/eluser]
can you start by capping the
Code:
class Base_c extends CI_Controller{

then

Code:
//then echo the value of

$this->auth->is_login();

and post back the values in the 2 pages
#7

[eluser]Near[/eluser]
Hi! Sorry for late reply. Everything is working fine. The capitalizations,declarations of variable. My_controller is located at applications/core... The only problem that i encounter is that when i request aq new page using redirect or other methods the controller variables are being set to FALSE. Do i have to store a session variable telling the user is logged in nd unset it after he logged out?
#8

[eluser]weboap[/eluser]
using session is the most common.

http://ellislab.com/codeigniter/user-gui...sions.html
Code:
$newdata = array(
                   'username'  => 'johndoe',
                   'email'     => '[email protected]',
                   'logged_in' => TRUE
               );

$this->session->set_userdata($newdata);


then
Code:
$logged_in = $this->session->userdata('logged_in');
if(!$logged_in){
.......
}
else
{
.......
}






Theme © iAndrew 2016 - Forum software by © MyBB