我有三个具有这些关系的模型:
允许 :
public function initialize()
{
$this->setSchema("ngd_demat");
$this->setSource("p_permission");
$this->belongsTo('idAction', Action::class, 'id', ['alias' => 'Action']);
}
行动 :
public function initialize()
{
$this->setSchema("ngd_demat");
$this->setSource("p_action");
$this->belongsTo('idResource', Resource::class, 'id', ['alias' => 'Resource']);
$this->hasMany('id', Permission::class, 'idAction', ['alias' => 'Permission']);
}
资源:
public function initialize()
{
$this->setSchema("ngd_demat");
$this->setSource("p_resource");
$this->hasMany('id',Action::class,'idResource', ['alias' => 'Action']);
}
我想要所有资源 libelle :
public static function isAllowed($role){
$resources = [];
$permission = Permission::find('idRole ='.$role.' AND isAllowed = 1');
foreach ($permission->action->resource as $resource){
array_push($resources, $resource->getLibelle());
}
return $resources;
}
它在 apache 错误日志中返回:
Undefined property: Phalcon\Mvc\Model\Resultset\Simple::$action Trying to get property 'resource' of non-object Invalid argument supplied for foreach()
我尝试将别名放在小写和大写中,使用 Permission::class 或“Security\Permission”或“Permission”的参考模型。我在 loader.php 中设置了安全命名空间。
提前致谢。