Redaxscript\Auth::setPermission PHP Метод

setPermission() публичный Метод

set the permission
С версии: 3.0.0
public setPermission ( string $key = null, integer $value = null )
$key string key of the permission
$value integer value of the permission
    public function setPermission($key = null, $value = null)
    {
        if (is_array($this->_permissionArray[$key])) {
            $value = array_merge($this->_permissionArray[$key], $value);
        }
        $this->_permissionArray[$key] = $value;
    }

Usage Example

Пример #1
0
 /**
  * process
  *
  * @since 3.0.0
  *
  * @return string
  */
 public static function process()
 {
     $auth = new Auth(Request::getInstance());
     $tableArray = ['categories', 'articles', 'extras', 'comments', 'groups', 'users'];
     /* set user */
     $auth->setUser('name', 'Demo');
     $auth->setUser('user', 'demo');
     $auth->setUser('email', 'demo@localhost');
     /* set permission */
     foreach ($tableArray as $value) {
         $auth->setPermission($value, [1, 2, 3]);
     }
     $auth->setPermission('settings', [1]);
     /* save user and permission */
     $auth->save();
     /* handle success */
     if ($auth->getStatus()) {
         return self::_success();
     }
     return self::_error();
 }