Welcome Guest, Not a member yet? Register   Sign In
use model in model called from a helper-file
#1

[eluser]butterbrei[/eluser]
Hi...

I try to write a helper-function for my views and try to use the following:
Code:
function user_loged() {
        $ci    = &get;_instance();
        $ci->load->model('UserModel');
        return $ci->UserModel->is_loged();
    }

The problem right now is, that I can't use another model. I try to call $this->BrowserModel->get(), but BrowserModel is not defined. It works fine in the Controller.

How to avoid this.

Thanks Smile
#2

[eluser]Eric Barnes[/eluser]
Code:
$ci->load->model('BrowserModel')
perhaps?
#3

[eluser]butterbrei[/eluser]
Also gets NULL.

Code:
function user_loged() {
        $ci    = &get;_instance();
        $ci->load->model('UserModel');
        $ci->load->model('BrowserModel');
        return $ci->UserModel->is_loged();
    }

and

Code:
public function generateSessionHash() {
    //var_dump($this->load->model('BrowserModel'));
    $lang        = $this->input->server('HTTP_ACCEPT_LANGUAGE');
    $ip            = $this->input->server('REMOTE_ADDR');
    var_dump($this->BrowserModel);
    $browser    = $this->BrowserModel->get();
        
    return sha1($lang . $ip);
}
#4

[eluser]LuckyFella73[/eluser]
You would have to load "BrowserModel" in "UserModel".

But I think your approach to check for a logged user is
not good practice. First of all Models are meant to be
undependant functions that just return data (see user guide).
And doing a login check in you view is against the principle
of MVC. You better set up a library or maybe use the ionauth
library for CI. The login check should be done in your controller(s).
Depending on where you want to have the check it might be
usefull to extend the controller class and do the check there.
#5

[eluser]butterbrei[/eluser]
Hi,

the helper-function is just for the template Wink
The BrowserModel is used to generate a second unique hash for the session.




Theme © iAndrew 2016 - Forum software by © MyBB