[eluser]wesleychristelis[/eluser]
hi I am going through the big name tutorials
however I am having an issue with my user model: SEE COMMENTS on ERRORS
Code:
<?php
/**
* @property mixed hashed_password
*/
class User extends ActiveRecord\Model
{
function set_password($plaintext)
{
$this->hashed_password = $this->hash_password($plaintext);
}
private function hash_password($password)
{
$salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
$hash = hash('sha256', $salt . $password);
return $salt . $hash;
}
private function validate_password($password)
{
$salt = substr($this->hashed_password, 0, 64);
$hash = substr($this->hashed_password, 64, 64);
$password_hash = hash('sha256', $salt . $password);
return $password_hash == $hash;
}
public static function validate_login($username, $password)
{
$user = User::find_by_username($username); //method find_by_username not found in class User
//referenced method is not found in subject class
if($user->validate_password($password) && $user) //method validate_password not found in class User
{
User::login($user->id);
return $user;
}
else
return FALSE;
}
public static function login($user_id)
{
$CI =& get_instance();
$CI->session->set_userdata('user_id', $user_id); //field session not found in class Ci_Controller
}
public static function logout()
{
$CI =& get_instance();
$CI->session->sess_destroy();
}
}
AND MY_Controller
Code:
class MY_Controller extends CI_Controller
{
var $user = FALSE;
// layout / autoview functionality
protected $layout_view = 'application';
protected $content_view = '';
protected $view_data = array();
function __construct()
{
parent::__construct();
$this->user = $this->session->userdata('user_id') ? User::find($this->session->userdata('user_id')) : FALSE; // as per errors above
}
public function _output($output)
{
// set the default content view
if($this->content_view !== FALSE && empty($this->content_view)) $this->content_view = $this->router->class . '/' . $this->router->method; //
// render the content view
$yield = file_exists(APPPATH . 'views/' . $this->content_view . EXT) ? $this->load->view($this->content_view, $this->view_data, TRUE) : FALSE;
// render the layout
if($this->layout_view)
echo $this->load->view('layouts/' . $this->layout_view, array('yield' => $yield), TRUE);
else
echo $yield;
}
}
the same erros for "router" , "view"
not sure what i am doing wrong have extended the classes and include the contructors as shown,