Welcome Guest, Not a member yet? Register   Sign In
$this errors in HMVC view
#1

[eluser]doccer[/eluser]
Question for those using HMVC. Why is it that the function that calls the view doesn't pass in its class variables?

ie I have this:

Code:
class Admin extends Controller {
    
    var $permissions;

    
    function Admin()
    {
        parent::Controller();
        
        $this->permissions = 1;

    }
        
        function index()
        {
            $this->load->view('admin');
        }
}

and in the $this->load->view('admin'); view I have

Code:
<?=$this->permissions?>

I get an error that it doesnt exist.

This works in a native CI install.

The only way I can get around this is to add
Code:
$this->load->caller = $this;

in the HMVC Controller class

then call

Code:
<?=$this->caller->permissions?>

in my view.

Any thoughts?
#2

[eluser]InsiteFX[/eluser]
There are two different ways to pass data to your views

SEE: Below.

Code:
class Admin extends Controller {
    
    var $permissions;
    
    function Admin()
    {
        parent::Controller();
        
        $this->permissions = 1;

    }
        
        function index()
        {
            $data['permissions' = $this->permissions;

            // there are two different ways to pass data to your views.
            $this->load->vars($data);
            
            or
            // pass $data as the second parameter to your view.
            $this->load->view('admin', $data);
        }
}

Enjoy
InsiteFX
#3

[eluser]doccer[/eluser]
I'm very familiar with passing an array to the view function. I'm simply asking if this issue is intended by HMVC or if it is a bug. Thanks.
#4

[eluser]InsiteFX[/eluser]
Also there are two different HMVC.

There's HMVC and then there's Modeluar Extensions HMVC.
So it would depend on which version you are using.

Did you try extending with MX_Controller?

Enjoy
InsiteFX
#5

[eluser]doccer[/eluser]
Sorry my apologies, its Modeluar Extensions HMVC. And no i have not extended it for this controller, I am in another Controller though. Would extending it to MX_Controller help? .. Ill try on Monday.. anyway.

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB