當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Application::createControllerByID方法代碼示例

本文整理匯總了PHP中yii\base\Application::createControllerByID方法的典型用法代碼示例。如果您正苦於以下問題:PHP Application::createControllerByID方法的具體用法?PHP Application::createControllerByID怎麽用?PHP Application::createControllerByID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\base\Application的用法示例。


在下文中一共展示了Application::createControllerByID方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getAuthItemsFromApp

 /**
  * @return array
  */
 protected function getAuthItemsFromApp()
 {
     $list = [];
     if (!is_dir($this->app->controllerPath)) {
         return $list;
     }
     $moduleAuthItemName = $this->className();
     foreach (FileHelper::findFiles($this->app->controllerPath, ['only' => ['*Controller.php']]) as $file) {
         $relativePath = basename($file);
         $controllerBaseClassName = substr($relativePath, 0, -4);
         // Removing .php
         $controllerName = substr($controllerBaseClassName, 0, -10);
         // Removing Controller
         $controllerClassName = ltrim($this->app->controllerNamespace . '\\' . $controllerBaseClassName);
         $ref = new \ReflectionClass($controllerClassName);
         if ($ref->isSubclassOf(Controller::class) || $ref->implementsInterface(AccessControlInterface::class)) {
             /** @var string $controllerClassName */
             $controllerAuthItemName = $controllerClassName;
             $controllerDescription = \Yii::t('admin/t', 'Access to the section "Application/{controller}"', ['controller' => $controllerName]);
             $controllerAuthItem = [$controllerAuthItemName => [$controllerDescription, Item::TYPE_PERMISSION, []]];
             $moduleAuthItem[$moduleAuthItemName][2][] = $controllerAuthItemName;
             $controllerInstance = $this->app->createControllerByID(Inflector::camel2id($controllerName));
             $actions = array_keys($controllerInstance->actions());
             $methods = $ref->getMethods(\ReflectionMethod::IS_PUBLIC);
             $actionsAuthItems = [];
             foreach (array_merge($actions, $methods) as $method) {
                 if (is_string($method)) {
                     $action = ucfirst($method);
                 } else {
                     /** @var \ReflectionMethod $method */
                     if (!preg_match('/^action([A-Z].*)$/', $method->getName(), $m)) {
                         continue;
                     }
                     $action = $m[1];
                 }
                 $actionAuthItemName = Rbac::operationName($controllerClassName, $action);
                 $actionDescription = \Yii::t('admin/t', 'Access to the action "Application/{controller}/{action}"', ['action' => $action, 'controller' => $controllerName]);
                 $actionsAuthItems[$actionAuthItemName] = [$actionDescription, Item::TYPE_PERMISSION, []];
                 $controllerAuthItem[$controllerAuthItemName][2][] = $actionAuthItemName;
             }
             $list = array_merge($list, $controllerAuthItem, $actionsAuthItems);
         }
     }
     return $list;
 }
開發者ID:omnilight,項目名稱:yz2-admin,代碼行數:48,代碼來源:AuthItemsFinder.php


注:本文中的yii\base\Application::createControllerByID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。