i need your help. Today, i was doing this code for 3 hours and Im really desperate now.
I have got a class for login/register. I make it with a help of Youtube-tutorial. My problem is, my remember function doesnt work. Look at this.
if($hashCheck->count()){
$user = new User($hashCheck->first()->user_id);
$user ->login();
}
In this part i make a new User object, giving a number (ID) like a param.. Next thing i do is...
public function __construct($user = null){
$this->_db = DB::getInstance();
$this->_sessionName = Config::get('session/session_name');
$this->_cookieName = Config::get('remember/cookie_name');
if(!$user){
if(Sessio::exists($this->_sessionName)){
$user = Sessio::get($this->_sessionName);
if($this->find($user)){
$this->_isLoggedIn = true;
}
else{
//logout
}
}
else{
$this->find($user);
}
}
}
now, var_dump($user) returns null so next is if(!$user){}.. it tries to call function find.. This is my function find
public function find($user = null){
var_dump($user);
if($user){
echo'probiha find';
$field = (is_numeric($user)) ? 'id' : 'jmeno';
$data = $this->_db->get('uzivatele', array($field,'=',$user));
if($data->count()){
echo 'data count';
$this->_data = $data->first();
return true;
}
}
return false;
}
But my $user is still null (and shoud be a number - ID)... When it is ID, function find will be work correct.
My question is, why is $user in construct null? :( When i done $user = new User($hashCheck->first()->user_id); it should be a number.. $hashCheck->first()->user_id returns a number (ID of user..) Thanks everybody for every answer :)
Aucun commentaire:
Enregistrer un commentaire