hammies
hammies

Reputation: 1435

cwebuser is undefined when function exists

cwebuser.isShop is not defined when a function exists. Not understanding why. I've searched around and all i find is the same question, no answer? What I am trying to do is to login from a module name shop but I get not defined. What else am I missing?

in my main module;

public function beforeControllerAction($controller, $action)
    {
    if(Yii::app()->getModule('shop')->user->isShop)  
        Yii::app()->getModule('shop')->user->setReturnUrl('shop/default/login');  
        else  
return false;
}

In webuser:

function isShop(){
        if (!isset(Yii::app()->user->user))
            return false;
        $user = Yii::app()->user->user;
        return intval($user->user_role_id) == 2;
    }

Upvotes: 1

Views: 125

Answers (1)

Simone
Simone

Reputation: 247

If you write

Yii::app()->getModule('shop')->user->isShop 

you are trying to access a variable of the Object user called isShop. Two cases:

  1. isShop is a variable
  2. isShop is a Virtual variable

Yours is the second case. This means that isShop is the result of calling the function getIsShop of the Object user, but your function is named only isShop.

Two Solutions:

  1. rename the function isShop to getIsShop
  2. call directly the function in the main module using

Yii::app()->getModule('shop')->user->isShop(). [see the round brackets]

Upvotes: 2

Related Questions