Search code examples
phpyii2rbac

Yii 2 RBAC Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: yii\rbac\DbManager::getItem()'


I was trying to create a console command for yii 2 rbac I'm getting exception:

'yii\base\UnknownMethodException' with message 'Calling unknown method: yii\rbac\DbManager::getItem()'

 protected function createItem($name,$type,$description='',$data=null)
{
$item=$this->_authManager->getItem($name);
if($item===null)
{
    $item = new Item;
    $item->name = $name;
    $item->type = $type;
    $item->description = $description;

    self::$newCount++;
    echo "creating new item $name \n";
    $item=$this->_authManager->addItem($item);
}
return $item;
}

Solution

  • Yii2 DbManager Docs - getItem() method is protected.

    PHP: Visibility - check out here for visibility in PHP.