[eluser]riwakawd[/eluser]
Hello I am trying to make custom validation for my login but getting error. Can't use method return value in write context error on line 32
Fatal error: Can't use method return value in write context in C:\xampp\htdocs\codeigniter-cms-1\admin\application\modules\backend\models\user\user_model.php on line 32
Code:
public function index() {
if($this->user_model->isLogged()) {
redirect('dashboard');
}
$this->ControllerCommonLogin();
}
public function ControllerCommonLogin() {
$data['title'] = $this->lang->line('heading_title');
$data['action'] = site_url('backend/login/validate');
$this->load->view('template/common/login', $data);
}
protected function validate() {
if (!empty($this->input->post('username')) || !empty($this->input->post('password') || !$this->user->login($this->input->post('username'), $this->input->post('password')))) {
$this->error['warning'] = $this->lang->line('error_login'); // Line 32
}
return !$this->error;
}
Model
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model {
private $user_id;
private $username;
public function __construct() {
parent::__construct();
if(!empty($this->session->userdata('user_id'))) {
$user_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix') . "user WHERE user_id = '" .$this->session->userdata('user_id') . "' AND status = '1'");
if($user_query->num_rows > 0) {
$this->user_id = $user_query->row('user_id');
$this->username = $user_query->row('username');
$this->db->query("UPDATE " . $this->input->post('db_prefix') . "user SET ip = '" . $this->input->ip_address()."' WHERE user_id = '" . (int)$this->session->userdata('user_id') . "'");
$user_group_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix') . "user_group WHERE user_group_id = '" . (int)$query->row('user_group_id') . "'");
} else {
$this->logout();
}
}
}
public function login($username, $password) {
$user_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix') . "user WHERE username = '" . $username . "' AND password = '" . $this->bcrypt->hash_password($this->input->post('password')), $password . "' AND status = '1'");
if ($user_query->num_rows) {
$this->session->set_userdata('user_id') = $user_query->row('user_id');
$this->user_id = $user_query->row('user_id');
$this->username = $user_query->row('username');
return true;
} else {
return false;
}
}
public function logout() {
$this->session->unset_userdata['user_id'];
$this->user_id = '';
$this->username = '';
}
public function isLogged() {
return $this->user_id;
}
}