Welcome Guest, Not a member yet? Register   Sign In
Model Issue
#1

[eluser]JayArias[/eluser]
Code:
<?PHP

class User extends Model{
    
    function User()
    {
        parent::Model();
    }
    
    function info($string)
    {
        $q = $this->db->query("SELECT * FROM `users` WHERE `username` = '".$this->session->userdata('username')."' AND `password` = '".$this->session->userdata('password')."'");
        $member = $q->row();
        $member->$string;
    }
}


Am I using the wrong method ??

I just want to load the model from with controllers and use $this->member->info('name'); and have it echo it
#2

[eluser]imn.codeartist[/eluser]
[quote author="Tego10122" date="1254804053"]
Code:
<?PHP

class User extends Model{
    
    function User()
    {
        parent::Model();
    }
    
    function info($string)
    {
        $q = $this->db->query("SELECT * FROM `users` WHERE `username` = '".$this->session->userdata('username')."' AND `password` = '".$this->session->userdata('password')."'");
        $member = $q->row();
        $member->$string;
    }
}


Am I using the wrong method ??

I just want to load the model from with controllers and use $this->member->info('name'); and have it echo it[/quote]

Just USE
Code:
print_r($member);
#3

[eluser]JayArias[/eluser]
I can't I want to echo certain information like , $this->member->info('username'); == 'jdoe'
#4

[eluser]imn.codeartist[/eluser]
what is your
$member->$string;

does ??
#5

[eluser]JayArias[/eluser]
Error me out I need to find a way to get information from it
#6

[eluser]imn.codeartist[/eluser]
can you exactly tell what are you trying to return from that Model class
#7

[eluser]JayArias[/eluser]
I want to be able to put the following in my controller....

$this->model_name->info_function('username'); and echo "the persons user name"
#8

[eluser]jedd[/eluser]
[quote author="Tego10122" date="1254884530"]I want to be able to put the following in my controller....

$this->model_name->info_function('username'); and echo "the persons user name"[/quote]

Well, once you put a return in front of the $member->$string; call in your model, you should be pretty much there.

A couple of extra comments, however.

You might want to have attributes in your User model that are populated by an init($username) method. This means you won't hit the database whenever you pull user, pass, prefs, etc. Instead you'd do something like (in your controller):
Code:
$this->User->load_details($username);

$user_name = $this->User->username;

Your query is a bit messy given you're matching user and pass - surely you only need to match user? Once you're authenticated, you don't need to keep the password around, especially not in the session data - it's not that it's insecure, it's just that it's irrelevant. (And possibly a tad insecure.)
#9

[eluser]JayArias[/eluser]
That makes no sense for that Ill just add everything to the session
#10

[eluser]jedd[/eluser]
[quote author="Tego10122" date="1254885562"]That makes no sense for that Ill just add everything to the session[/quote]

On the subject of not making sense.

Are you saying that none of the three things I said helped with your problem or made sense?




Theme © iAndrew 2016 - Forum software by © MyBB