本文整理汇总了PHP中yii\web\Controller::className方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::className方法的具体用法?PHP Controller::className怎么用?PHP Controller::className使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\web\Controller
的用法示例。
在下文中一共展示了Controller::className方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
parent::init();
Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, function ($event) {
$event->sender->view->params['pagelabel'] = 'User Management System';
});
}
示例2: bootstrap
public function bootstrap($app)
{
\Yii::$classMap = array_merge(\Yii::$classMap, ['yii\\grid\\CheckboxColumn' => '@yii/adminUi/widget/CheckboxColumn.php', 'yii\\grid\\ActionColumn' => '@yii/adminUi/widget/ActionColumn.php']);
$app->set('view', ['class' => 'yii\\web\\View', 'theme' => ['pathMap' => ['@backend/views' => '@backend/themes/adminui']]]);
$app->set('assetManager', ['class' => 'yii\\web\\AssetManager', 'bundles' => ['yii\\widgets\\ActiveFormAsset' => ['js' => [], 'depends' => ['yii\\adminUi\\assetsBundle\\AdminUiActiveForm']], 'yii\\grid\\GridViewAsset' => ['depends' => ['app\\assets\\AppAsset']]], 'linkAssets' => true]);
Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, function ($event) {
if (in_array($event->action->id, ['login', 'forgot', 'reset-password']) && in_array('backend', explode("\\", $event->sender->className()))) {
$event->sender->layout = '//blank';
}
});
}
示例3: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!Yii::$app instanceof Application) {
return;
}
Event::on(Controller::className(), 'beforeAction', [$this, 'beforeActionAccess']);
if ($this->removeDeniedLinks) {
Event::on(Response::className(), 'afterPrepare', [$this, 'responseAfterPrepare']);
}
}
示例4: rules
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(parent::rules(), [[['modelClass', 'formModelClass', 'baseClass', 'controllerClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['searchModelClass'], 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class must not be equal to Model Class.'], [['baseClass'], 'required'], [['modelClass', 'modelClass', 'controllerClass', 'baseControllerClass', 'searchModelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters are allowed.'], [['baseClass'], 'match', 'pattern' => '/^[\\w\\\\]+$/', 'message' => 'Only word characters and backslashes are allowed.'], [['controllerClass', 'searchModelClass'], 'validateNewClass'], [['modelClass', 'formModelClass'], 'validateModelClass', 'skipOnEmpty' => false], [['baseClass', 'modelClass'], 'validateClass', 'params' => ['extends' => Model::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerClass'], function ($field) {
if ($this->{$field}) {
if (!$this->formModelClass) {
$this->addError('formModelClass', 'formModelClass required');
}
if (!$this->searchModelClass) {
$this->addError('searchModelClass', 'searchModelClass required');
}
}
}]]);
}
示例5: bootstrap
public function bootstrap($app)
{
/*@var $app Application*/
if ($app->request->get('blankLayout') === 'true') {
Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, function ($event) {
if (file_exists(Yii::getAlias('@app') . DIRECTORY_SEPARATOR . 'composer.json')) {
$replace = '@app';
} else {
$replace = '@app/..';
}
$event->action->controller->layout = $replace . str_replace(realpath(Yii::getAlias($replace)), '', str_replace("\\", "/", __DIR__ . DIRECTORY_SEPARATOR . 'widgets' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . 'blank.php'));
});
}
}
示例6: rules
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(parent::rules(), [
[['controllerClass', 'modelClass', 'searchModelClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'],
[['modelClass', 'controllerClass', 'baseControllerClass', 'indexWidgetType'], 'required'],
[['searchModelClass'], 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class must not be equal to Model Class.'],
[['modelClass', 'controllerClass', 'baseControllerClass', 'searchModelClass'], 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'],
[['modelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]],
[['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]],
[['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'],
[['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.'],
[['controllerClass', 'searchModelClass'], 'validateNewClass'],
[['indexWidgetType'], 'in', 'range' => ['grid', 'list']],
[['modelClass'], 'validateModelClass'],
[['enableI18N'], 'boolean'],
[['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false],
['viewPath', 'safe'],
]);
}
示例7: bootstrap
public function bootstrap($app)
{
$events = [Controller::EVENT_BEFORE_ACTION];
foreach ($events as $eventName) {
Event::on(Controller::className(), $eventName, function ($event) use($app, $eventName) {
Libs::mkView($app, $eventName, $event);
});
}
$events = [ActiveRecord::EVENT_AFTER_INSERT, ActiveRecord::EVENT_BEFORE_UPDATE, ActiveRecord::EVENT_BEFORE_DELETE];
$res0 = false;
foreach ($events as $eventName) {
Event::on(ActiveRecord::className(), $eventName, function ($event) use($app, $eventName) {
$model = $event->sender;
$res0 = Libs::mkVersion($app, $eventName, $model);
});
}
if ($res0) {
$events = [ActiveRecord::EVENT_AFTER_UPDATE, ActiveRecord::EVENT_AFTER_DELETE];
foreach ($events as $eventName) {
Event::on(ActiveRecord::className(), $eventName, function ($event) use($app, $eventName, $res0) {
$res = true;
$model = $event->sender;
foreach ($model->attributes as $a => $v) {
$m = $res0[1];
if ($eventName == ActiveRecord::EVENT_AFTER_UPDATE) {
$res = $m[$a] != $v ? false : $res;
} elseif ($eventName == ActiveRecord::EVENT_AFTER_DELETE) {
$res = $m[$a] != null ? false : $res;
}
}
if (!$res) {
$route = Route::findOne($res0[0]);
if ($route) {
$route->delete();
}
}
});
}
}
}
示例8: rules
public function rules()
{
return ArrayHelper::merge(parent::rules(), [[['columns'], MultipleModelValidator::className(), 'baseModel' => WidgetsCrud::className(), 'skipOnEmpty' => true], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'filter', 'filter' => 'trim'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'required'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.']]);
}
示例9: parseRequest
/**
* Parses the given request and returns the corresponding route and parameters.
* @param \yii\web\UrlManager $manager the URL manager
* @param Request $request the request component
* @return array|bool the parsing result. The route and the parameters are returned as an array.
* @throws ForbiddenHttpException
*/
public function parseRequest($manager, $request)
{
$menuMap = $this->menuManager->getMenuMap();
if (!($pathInfo = $request->getPathInfo() or $pathInfo = ($mainMenu = $menuMap->getMainMenu()) ? $mainMenu->path : null)) {
return false;
}
// помечаем как активные все пункты меню которые ссылаются на тотже урл что в запросе
$this->menuManager->setActiveMenuIds($menuMap->getMenuIdsByLink($request->getUrl()));
// ищем пункт меню, чей путь совпадает с путем в запросе
if ($menu = $menuMap->getMenuByPathRecursive($pathInfo)) {
// определяем в каком контексте ("Точный" или "Подходящий") рассматривать активное меню
$menu->setContext($menu->path === $pathInfo ? MenuItem::CONTEXT_PROPER : MenuItem::CONTEXT_APPLICABLE);
// устанавливаем найденный пункт меню в качестве активного
$this->menuManager->setActiveMenu($menu);
// добавляем данный пункт в список активных пунктов меню
$this->menuManager->addActiveMenuId($menu->id);
if ($menu->getContext() === MenuItem::CONTEXT_PROPER) {
//при "точном" совпадении, метаданные меню перекрывают метаднные контроллера
Yii::$app->getView()->on(View::EVENT_BEGIN_PAGE, [$this, 'applyMetaData']);
} else {
//при "подходящем" устанавливаются по умолчанию
$this->applyMetaData();
}
} else {
return false;
}
// устанавливаем макет приложению
Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, [$this, 'applyLayout']);
// Проверка на доступ к пунтку меню
if (!empty($menu->access_rule) && !Yii::$app->user->can($menu->access_rule)) {
if (Yii::$app->user->getIsGuest()) {
Yii::$app->user->loginRequired();
} else {
throw new ForbiddenHttpException(Yii::t('gromver.platform', 'You have no rights for access to this section of the site.'));
}
}
if ($menu->getContext() === MenuItem::CONTEXT_PROPER) {
// при "точном" контексте пункта меню, возвращаем роут на компонент
return $menu->parseUrl();
} else {
/*
* при "подходящем" контексте пункта меню, необходимо на основании оставшейся части пути
* и информации из пункта меню маршрутизировать приложение
*/
$requestRoute = substr($pathInfo, mb_strlen($menu->path) + 1);
list($menuRoute, $menuParams) = $menu->parseUrl();
$requestInfo = new MenuRequestInfo(['menuMap' => $menuMap, 'menuRoute' => $menuRoute, 'menuParams' => $menuParams, 'requestRoute' => $requestRoute, 'requestParams' => $request->getQueryParams()]);
foreach ($this->_parseUrlRules as $rule) {
if ($result = $rule->process($requestInfo, $this)) {
return $result;
}
}
return false;
}
}
示例10: rules
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(parent::rules(), [[['controllerClass', 'modelClass', 'searchModelClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['modelClass', 'controllerClass', 'baseControllerClass'], 'required'], [['searchModelClass'], 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class 必须继承自 Model Class.'], [['modelClass', 'controllerClass', 'baseControllerClass', 'searchModelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => '只有字母和"\\"允许使用.'], [['modelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => '控制器名字必须以:"Controller".结尾'], [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => '控制器名字必须是大写字母开头.'], [['controllerClass', 'searchModelClass'], 'validateNewClass'], [['modelClass'], 'validateModelClass'], [['enableI18N'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false], ['viewPath', 'safe']]);
}
示例11: rules
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(parent::rules(), [[['db', 'nsModel', 'viewPath', 'queryNs', 'nsController', 'nsSearchModel', 'tableName', 'modelClass', 'searchModelClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['tableName', 'baseControllerClass', 'indexWidgetType', 'db'], 'required'], [['tableName'], 'match', 'pattern' => '/^(\\w+\\.)?([\\w\\*]+)$/', 'message' => 'Only word characters, and optionally an asterisk and/or a dot are allowed.'], [['tableName'], 'validateTableName'], [['modelClass', 'baseControllerClass', 'searchModelClass', 'db', 'queryClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['db'], 'validateDb'], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.'], [['indexWidgetType'], 'in', 'range' => ['grid', 'list']], [['enableI18N', 'generateRelations', 'generateSearchModel', 'pluralize', 'expandable', 'exportable', 'pdf', 'loggedUserOnly'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false], [['viewPath', 'skippedRelations', 'skippedColumns', 'controllerClass', 'blameableValue', 'nameAttribute', 'hiddenColumns', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy', 'UUIDColumn'], 'safe']]);
}
示例12: rules
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(parent::rules(), [[['moduleID', 'controllerID', 'actions', 'formActions', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['controllerID', 'baseControllerClass'], 'required'], [['controllerID'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-\\/]*$/', 'message' => 'Only a-z, 0-9, dashes (-) and slashes (/) are allowed.'], [['actions', 'formActions'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-,\\s]*$/', 'message' => 'Only a-z, 0-9, dashes (-), spaces and commas are allowed.'], [['baseControllerClass', 'modelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['scenarioName'], 'match', 'pattern' => '/^[\\w\\-]+$/', 'message' => 'Only word characters and dashes are allowed.'], [['modelClass'], 'validateClass', 'params' => ['extends' => Model::className()]], [['moduleID'], 'validateModuleID']]);
}
示例13: rules
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(parent::rules(), [[['loginModelClass', 'controllerClass', 'viewPath'], 'filter', 'filter' => 'trim'], [['loginModelClass', 'controllerClass', 'viewPath'], 'required'], [['loginModelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['loginModelClass'], 'validateClass', 'params' => ['extends' => Model::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.'], [['controllerClass'], 'validateNewClass'], [['viewPath'], 'match', 'pattern' => '/^@?\\w+[\\-\\/\\w]*$/', 'message' => 'Only word characters, dashes, slashes and @ are allowed.'], [['viewPath'], 'validatePath'], [['enableI18N'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false]]);
}
示例14: rules
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(parent::rules(), [[['modelClass'], 'required'], [['modelClass', 'baseControllerClass', 'extraActions'], 'filter', 'filter' => 'trim'], [['modelClass', 'controllerClass', 'baseControllerClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['modelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.'], [['controllerClass'], 'validateNewClass'], [['modelClass'], 'validateModelClass'], [['controllerActionIndexEnabled', 'controllerActionCreateEnabled', 'controllerActionUpdateEnabled', 'controllerActionDeleteEnabled', 'controllerActionApproveEnabled', 'controllerActionDisapproveEnabled', 'controllerActionDeleteSelectedEnabled', 'controllerActionApproveSelectedEnabled', 'controllerActionDisapproveSelectedEnabled', 'controllerActionDetailViewEnabled'], 'boolean', 'on' => 'controller'], ['headingTitle', 'string', 'on' => 'index'], ['columns', 'safe', 'on' => 'index'], [['toolbarCreateButtonEnabled', 'toolbarApproveButtonEnabled', 'toolbarDisapproveButtonEnabled', 'toolbarDeleteButtonEnabled', 'toolbarRefreshButtonEnabled', 'checkboxColumnEnabled', 'actionColumnEnabled', 'actionApproveEnabled', 'actionDisapproveEnabled', 'idColumnEnabled', 'createdColumnEnabled', 'updatedColumnEnabled', 'detailColumnEnabled', 'pjax', 'condensed', 'hover', 'showPageSummary', 'resizableColumns', 'floatHeader', 'perfectScrollbar', 'toggleData', 'showHeader', 'bootstrap', 'bordered', 'striped'], 'boolean', 'on' => 'index'], ['columns', 'safe', 'on' => 'index'], ['columns', 'safe', 'on' => 'index']]);
}
示例15: rules
/**
* @inheritdoc
*/
public function rules()
{
return [[['template'], 'required', 'message' => 'A code template must be selected.'], [['template'], 'validateTemplate'], [['controllerClass', 'modelClass', 'baseControllerClass', 'baseModelClass'], 'filter', 'filter' => 'trim'], [['modelClass', 'controllerClass', 'baseControllerClass', 'baseModelClass'], 'required'], [['modelClass', 'controllerClass', 'baseControllerClass', 'baseModelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseModelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.'], [['controllerClass', 'modelClass'], 'validateNewClass'], [['baseModelClass'], 'validateBaseModelClass'], [['enableI18N', 'isImage'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false], ['viewPath', 'safe']];
}