本文整理汇总了PHP中yii\base\Module::className方法的典型用法代码示例。如果您正苦于以下问题:PHP Module::className方法的具体用法?PHP Module::className怎么用?PHP Module::className使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Module
的用法示例。
在下文中一共展示了Module::className方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bootstrap
/**
* Bootstrap method to be called during application bootstrap stage.
* @param Application $app the application currently running
*/
public function bootstrap($app)
{
/** @var Module $module */
if (($module = $app->getModule('admin')) == null || !$module instanceof Module) {
return;
}
$class = 'nullref\\admin\\models\\Admin';
$definition = $module->adminModel;
if ($module->enableRbac) {
$module->setComponents(['authManager' => $module->authManager, 'roleContainer' => $module->roleContainer]);
}
Yii::$container->set($class, $definition);
$className = is_array($definition) ? $definition['class'] : $definition;
Event::on(AdminQuery::className(), AdminQuery::EVENT_INIT, function (Event $e) use($class, $className) {
if ($e->sender->modelClass == $class) {
$e->sender->modelClass = $className;
}
});
/** I18n */
if (!isset($app->get('i18n')->translations['admin*'])) {
$app->i18n->translations['admin*'] = ['class' => PhpMessageSource::className(), 'basePath' => '@nullref/admin/messages'];
}
if ($app instanceof WebApplication) {
Yii::$app->setComponents(['admin' => ['class' => 'nullref\\admin\\components\\User', 'identityClass' => $className, 'loginUrl' => ['admin/login']]]);
$app->urlManager->addRules(['/admin/login' => '/admin/main/login']);
$app->urlManager->addRules(['/admin/logout' => '/admin/main/logout']);
Event::on(BaseModule::className(), BaseModule::EVENT_BEFORE_ACTION, function () use($module) {
if (Yii::$app->controller instanceof IAdminController) {
/** @var Controller $controller */
$controller = Yii::$app->controller;
$controller->layout = $module->layout;
if ($controller->module != $module) {
$controller->module->setLayoutPath($module->getLayoutPath());
}
if (!isset($controller->behaviors()['access'])) {
$controller->attachBehavior('access', AccessControl::className());
}
Yii::$app->errorHandler->errorAction = $module->errorAction;
}
});
} elseif ($app instanceof ConsoleApplication) {
if ($module !== null) {
/** @var Module $module */
if ($module->enableRbac) {
$module->controllerMap['rbac'] = ['class' => 'nullref\\admin\\console\\RbacController'];
}
}
}
Event::on(Module::className(), Module::EVENT_BEFORE_INIT, function (Event $event) use($app) {
$module = $event->sender;
/** @var Module $module */
if ($module->enableRbac) {
if ($app instanceof ConsoleApplication) {
$module->controllerMap['rbac'] = ['class' => 'nullref\\admin\\console\\RbacController'];
}
$module->setComponents(['authManager' => $module->authManager, 'roleContainer' => $module->roleContainer]);
}
});
if (YII_ENV_DEV && class_exists('yii\\gii\\Module')) {
Event::on(Gii::className(), Gii::EVENT_BEFORE_ACTION, function (Event $event) {
/** @var Gii $gii */
$gii = $event->sender;
$gii->generators['crud'] = ['class' => 'yii\\gii\\generators\\crud\\Generator', 'templates' => ['admin-crud' => '@nullref/admin/generators/crud/admin']];
$gii->generators['stuff'] = ['class' => 'nullref\\admin\\generators\\stuff\\Generator', 'templates' => ['default' => '@nullref/admin/generators/stuff/default']];
});
}
}