本文整理汇总了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;
}