Код: Выделить всё
// main.php
'authManager' => array(
'class' => 'CPhpAuthManager',
'defaultRoles' => array('guest','authenticated','applicant','admin')
),
Код: Выделить всё
<?php
// auth.php
return array(
// ...
'authenticated' => array(
'type' => CAuthItem::TYPE_ROLE,
'description' => 'Пользователь',
'children' => array( 'guest' ),
'bizRule' => 'return !Yii::app()->user->isGuest ? true : false;',
'data' => null
),
'applicant' => array(
'type' => CAuthItem::TYPE_ROLE,
'description' => 'Соискатель',
'children' => array( 'authenticated' ),
'data' => null
),
// ...
Код: Выделить всё
var_dump(
'Authenticated', $this->checkAccess('authenticated'),
'Applicant', $this->checkAccess('applicant')
);
// Результат
// string(13) "Authenticated" bool(true)
// string(9) "Applicant" bool(true)
Код: Выделить всё
'bizRule' => 'return false;',
// Результат того же var_dump
// string(13) "Authenticated" bool(false)
// string(9) "Applicant" bool(true)
Код: Выделить всё
if(in_array($itemName,$this->defaultRoles))
return true;
Код: Выделить всё
foreach($this->_children as $parentName=>$children)
{
if(isset($children[$itemName]) && $this->checkAccess($parentName,$userId,$params))
return true;
}
1. Если роль задана в defaultRoles, то как ни указывай children
Код: Выделить всё
'authenticated' => array(
'children' => array( 'applicant' ),
)
// или
'applicant' => array(
'children' => array( 'authenticated' )
)
2. Если же мы уберем нашу роль из defaultRoles, то проверка дойдет до цикла, в котором по логике цикла мы должны указать children вот так:
Код: Выделить всё
'authenticated' => array(
'children' => array( 'applicant' ),
)
По моей логике это должно работать так. У нас есть роль authenticated, мы от нее наследуем роль applicant. И три правила: 1) если bizRule у authenticated возвращает TRUE, а у applicant оно не указано, то в целом checkAccess возвращает true. 2) Если у applicant указан свой bizRule то checkAccess уже ориентируется на него. 3) Надо иметь возможность проверить что возвращает родительская роль. Т.е. в bizRule для applicant укзазать что то типа: return $checkParentAccess && $myExpressionReturnBoolValue;