Welcome Guest, Not a member yet? Register   Sign In
methods and fields not recognized
#1

[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,
#2

[eluser]InsiteFX[/eluser]
For one you cannot extend any of the database stuff.

Code:
class User extends ActiveRecord\Model // <- this is totaly wrong.

if(User::validate_password($password) && $user)

$user = User::find_by_username($username); // this method doe's not exist in the model

//field session not found in class Ci_Controller
Did you load the session library?

I think you need to re-think your code.
#3

[eluser]Aken[/eluser]
He's using a tutorial that extends the PHP ActiveRecord library that has been added to CI.

I think you need to watch those videos on Big Time, because you're probably missing an autoload function or namespace or something. It'd be difficult / time-consuming for any of us to go through those tutorials and wonder what you missed.

[Edited to sound less like a jerk.]
#4

[eluser]wesleychristelis[/eluser]
I will do so .. thanks guys... appreciated...

oh and for the record

the method :

User::find_by_username($username);

it uses reflection , so the method need not be declared in the class.

reflection does it for you....




Theme © iAndrew 2016 - Forum software by © MyBB