当前位置: 首页>>代码示例>>PHP>>正文


PHP User::className方法代码示例

本文整理汇总了PHP中yii\web\User::className方法的典型用法代码示例。如果您正苦于以下问题:PHP User::className方法的具体用法?PHP User::className怎么用?PHP User::className使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\web\User的用法示例。


在下文中一共展示了User::className方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getUser

 /**
  * Get user
  * @return User
  */
 public function getUser()
 {
     if (!$this->_user instanceof User) {
         $this->_user = Instance::ensure($this->_user, User::className());
     }
     return $this->_user;
 }
开发者ID:thinkwill,项目名称:yii2-admin,代码行数:11,代码来源:AccessControl.php

示例2: interception

 public function interception($event)
 {
     if (!isset(Yii::$app->i18n->translations['db_rbac'])) {
         Yii::$app->i18n->translations['db_rbac'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'sourceLanguage' => 'ru-Ru', 'basePath' => '@developeruz/db_rbac/messages'];
     }
     $route = Yii::$app->getRequest()->resolve();
     //Проверяем права по конфигу
     $this->createRule();
     $user = Instance::ensure(Yii::$app->user, User::className());
     $request = Yii::$app->getRequest();
     $action = $event->action;
     if (!$this->cheсkByRule($action, $user, $request)) {
         //И по AuthManager
         if (!$this->checkPermission($route)) {
             //Если задан $login_url и пользователь не авторизован
             if (Yii::$app->user->isGuest && $this->login_url) {
                 Yii::$app->response->redirect($this->login_url)->send();
                 exit;
             }
             //Если задан $redirect_url
             if ($this->redirect_url) {
                 Yii::$app->response->redirect($this->redirect_url)->send();
                 exit;
             } else {
                 throw new ForbiddenHttpException(Yii::t('db_rbac', 'Недостаточно прав'));
             }
         }
     }
 }
开发者ID:developeruz,项目名称:yii2-db-rbac,代码行数:29,代码来源:AccessBehavior.php

示例3: init

 /**
  * 初始化方法
  */
 public function init()
 {
     parent::init();
     //获取user实例
     $this->user = Instance::ensure($this->user, User::className());
     $this->user_info = $this->user->identity;
 }
开发者ID:wangpengzhen,项目名称:web,代码行数:10,代码来源:RbacControl.php

示例4: init

 /**
  * Initializes the [[rules]] array by instantiating rule objects from configurations.
  */
 public function init()
 {
     parent::init();
     $this->user = Instance::ensure($this->user, User::className());
     if ($this->user->identity !== null) {
         $this->user->identity->getRules();
     }
 }
开发者ID:rajanishtimes,项目名称:basicyii,代码行数:11,代码来源:AccessControl.php

示例5: beforeLogin

 /**
  * when user login in backend , it should be 'Administrator' or ,'Merchant'
  */
 public static function beforeLogin()
 {
     Event::on(\yii\web\User::className(), \yii\web\User::EVENT_BEFORE_LOGIN, function ($event) {
         $user = $event->identity;
         $auth = new DbManager();
         $auth->init();
         $role = $auth->getRolesByUser($user->id);
         $event->isValid = in_array(current($role)->name, ['Administrator', 'Merchant']);
     });
 }
开发者ID:shuangjie,项目名称:galaxy,代码行数:13,代码来源:UserEvent.php

示例6: bootstrap

 /**
  * @param \yii\base\Application $app
  */
 public function bootstrap($app)
 {
     Event::on(User::className(), User::EVENT_AFTER_LOGIN, function () {
         $storage = Instance::ensure(\Yii::$app->cart->storage, MultipleStorage::className());
         if (get_class($storage) == 'hscstudio\\cart\\MultipleStorage') {
             $cart = Instance::ensure(\Yii::$app->cart, Cart::className());
             $storage->sync($cart);
         }
     });
 }
开发者ID:hscstudio,项目名称:yii2-cart,代码行数:13,代码来源:CartBootstrap.php

示例7: init

 /**
  * Initialize
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     $this->authManager = Instance::ensure($this->authManager, BaseManager::className());
     $this->user = Instance::ensure($this->user, User::className());
     if (empty($this->cache)) {
         $this->cache = $this->createCacheComponent();
     } else {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }
开发者ID:rmrevin,项目名称:yii2-rbac-command,代码行数:16,代码来源:Command.php

示例8: init

 /**
  * Initializes the [[rules]] array by instantiating rule objects from configurations.
  */
 public function init()
 {
     if ($this->user === null) {
         $this->user = Adm::getInstance()->user;
     }
     $this->user = Instance::ensure($this->user, User::className());
     foreach ($this->rules as $i => $rule) {
         if (is_array($rule)) {
             $this->rules[$i] = Yii::createObject(array_merge($this->ruleConfig, $rule));
         }
     }
 }
开发者ID:pavlinter,项目名称:yii2-adm,代码行数:15,代码来源:AccessControl.php

示例9: userLoginAfter

 /**
  * 注册登录事件
  * @throws \Exception
  * @return boolean
  */
 public static function userLoginAfter()
 {
     Event::on(User::className(), User::EVENT_AFTER_LOGIN, function ($event) {
         // user identity
         if (isset($event->identity) && $event->identity instanceof \common\models\User) {
             $user = $event->identity;
             $attrs = [];
             foreach ($attrs as $_attr) {
                 \Yii::$app->session->set($_attr, isset($user->{$_attr}) ? $user->{$_attr} : false);
             }
         }
         return true;
     });
 }
开发者ID:johnny618,项目名称:love,代码行数:19,代码来源:SessionHelper.php

示例10: init

 public function init()
 {
     $this->user = Instance::ensure($this->user, User::className());
     $rolesObject = Yii::$app->authManager->getRolesByUser($this->user->id);
     if (!empty($rolesObject)) {
         foreach ($rolesObject as $roles => $object) {
             foreach ($object->data as $route) {
                 $this->_actions[] = $route;
             }
         }
     }
     $this->rules = [['actions' => $this->_actions, 'allow' => true]];
     parent::init();
 }
开发者ID:nicovicz,项目名称:portalctv,代码行数:14,代码来源:AccessControl.php

示例11: interception

 public function interception($event)
 {
     $route = Yii::$app->getRequest()->resolve();
     //Проверяем права по конфигу
     $this->createRule();
     $user = Instance::ensure(Yii::$app->user, User::className());
     $request = Yii::$app->getRequest();
     $action = $event->sender->requestedAction;
     if (!$this->cheсkByRule($action, $user, $request)) {
         //И по AuthManager
         if (!$this->checkPermission($route)) {
             throw new BadRequestHttpException('Не достаточно прав');
         }
     }
 }
开发者ID:halk2269,项目名称:yii2-db-rbac,代码行数:15,代码来源:AccessBehavior.php

示例12: init

 public function init()
 {
     /** @var $module Module */
     if (empty($this->user) && ($module = Yii::$app->getModule('admin')) != null) {
         $this->user = $module->adminComponent;
     }
     ActionFilter::init();
     if (empty($this->rules)) {
         $this->rules = [['actions' => [], 'allow' => true, 'roles' => ['@']]];
     }
     $this->user = Instance::ensure($this->user, User::className());
     foreach ($this->rules as $i => $rule) {
         if (is_array($rule)) {
             $this->rules[$i] = Yii::createObject(array_merge($this->ruleConfig, $rule));
         }
     }
 }
开发者ID:NullRefExcep,项目名称:yii2-admin,代码行数:17,代码来源:AccessControl.php

示例13: interception

 public function interception($event)
 {
     if (!isset(Yii::$app->i18n->translations['db_rbac'])) {
         Yii::$app->i18n->translations['db_rbac'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'sourceLanguage' => 'ru-Ru', 'basePath' => '@developeruz/db_rbac/messages'];
     }
     $route = Yii::$app->getRequest()->resolve();
     //Проверяем права по конфигу
     $this->createRule();
     $user = Instance::ensure(Yii::$app->user, User::className());
     $request = Yii::$app->getRequest();
     $action = $event->action;
     if (!$this->cheсkByRule($action, $user, $request)) {
         //И по AuthManager
         if (!$this->checkPermission($route)) {
             throw new ForbiddenHttpException(Yii::t('db_rbac', 'Недостаточно прав'));
         }
     }
 }
开发者ID:welleman,项目名称:yii2-db-rbac,代码行数:18,代码来源:AccessBehavior.php

示例14: actionJson

 /**
  * Run a generation of swagger json-document
  * @throws \yii\base\InvalidConfigException
  */
 public function actionJson()
 {
     // workaround for identity absence in console application
     Yii::$container->set('user', ['class' => User::className(), 'identityClass' => 'common\\models\\User']);
     // Document generation
     $doc = new Document();
     Yii::$app->set('doc', $doc);
     $controllers = $this->getControllers();
     /** @var \yii\base\Controller $controller */
     foreach ($controllers as $key => $controller) {
         $tag = new Tag();
         $tag->name = $key;
         $doc->addTag($tag);
         $actions = $this->getActions($controller);
         foreach ($actions as $actionName => $action) {
             $doc->handleAction($action);
         }
     }
     $doc->generateFile(Yii::getAlias($this->module->jsonPath));
     $this->stdout('Done' . PHP_EOL);
 }
开发者ID:VictorGub,项目名称:yii2-swagger,代码行数:25,代码来源:GenerateController.php

示例15: bootstrap

 /** @inheritdoc */
 public function bootstrap($app)
 {
     /** @var $module Module */
     if ($app->hasModule('users') && ($module = $app->getModule('users')) instanceof Module) {
         $this->_modelMap = array_merge($this->_modelMap, $module->modelMap);
         foreach ($this->_modelMap as $name => $definition) {
             $class = "mii\\modules\\users\\models\\" . $name;
             \Yii::$container->set($class, $definition);
             $modelName = is_array($definition) ? $definition['class'] : $definition;
             $module->modelMap[$name] = $modelName;
             if (in_array($name, ['User', 'Profile', 'Token', 'Account'])) {
                 \Yii::$container->set($name . 'Query', function () use($modelName) {
                     return $modelName::find();
                 });
             }
         }
         \Yii::$container->setSingleton(Finder::className(), ['userQuery' => \Yii::$container->get('UserQuery'), 'profileQuery' => \Yii::$container->get('ProfileQuery'), 'tokenQuery' => \Yii::$container->get('TokenQuery'), 'accountQuery' => \Yii::$container->get('AccountQuery')]);
         if ($app instanceof ConsoleApplication) {
             $module->controllerNamespace = 'mii\\modules\\users\\commands';
             $app->get('i18n')->translations['users*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages'];
         } else {
             try {
                 $app->user->enableAutoLogin = true;
                 $app->user->loginUrl = ['/users/security/login'];
                 $app->user->identityClass = $module->modelMap['User'];
             } catch (InvalidConfigException $e) {
                 $app->set('user', ['class' => User::className(), 'enableAutoLogin' => true, 'loginUrl' => ['/users/security/login'], 'identityClass' => $module->modelMap['User']]);
             }
             $configUrlRule = ['prefix' => $module->urlPrefix, 'rules' => $module->urlRules];
             if ($module->urlPrefix != 'users') {
                 $configUrlRule['routePrefix'] = 'users';
             }
             $app->get('urlManager')->rules[] = new GroupUrlRule($configUrlRule);
             $app->get('urlManager')->addRules(['PUT,PATCH /' . $this->id . '/apis/<id>' => $this->id . '/api/update', 'DELETE /' . $this->id . '/apis/<id>' => $this->id . '/api/delete', 'GET,HEAD /' . $this->id . '/apis/<id>' => $this->id . '/api/view', 'POST /' . $this->id . '/apis' => $this->id . '/api/create', 'GET,HEAD /' . $this->id . '/apis' => $this->id . '/api/index', 'OPTIONS /' . $this->id . '/apis/<id>' => $this->id . '/api/options', 'OPTIONS /' . $this->id . '/apis' => $this->id . '/api/options'], false);
             if (!$app->has('authClientCollection')) {
                 $app->set('authClientCollection', ['class' => Collection::className()]);
             }
         }
         $app->get('i18n')->translations['users*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages'];
         $defaults = ['welcomeSubject' => \Yii::t('users', 'Welcome to {0}', \Yii::$app->name), 'confirmationSubject' => \Yii::t('users', 'Confirm account on {0}', \Yii::$app->name), 'reconfirmationSubject' => \Yii::t('users', 'Confirm email change on {0}', \Yii::$app->name), 'recoverySubject' => \Yii::t('users', 'Complete password reset on {0}', \Yii::$app->name)];
         \Yii::$container->set('mii\\modules\\users\\Mailer', array_merge($defaults, $module->mailer));
     }
 }
开发者ID:pointdnd,项目名称:yii2-modular,代码行数:44,代码来源:Module.php


注:本文中的yii\web\User::className方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。