本文整理汇总了PHP中yii\web\Controller类的典型用法代码示例。如果您正苦于以下问题:PHP Controller类的具体用法?PHP Controller怎么用?PHP Controller使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Controller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeAction
/**
* @param \yii\base\Action $action
*/
public function beforeAction($action)
{
if ($action->controller->id == 'default') {
\yii\web\Controller::redirect('/staff/admin');
}
return true;
}
示例2: getActions
/**
* Returns all available actions of the specified controller.
* @param Controller $controller the controller instance
* @return array all available action IDs.
*/
public function getActions($controller)
{
$actions = array_keys($controller->actions());
$class = new \ReflectionClass($controller);
foreach ($class->getMethods() as $method) {
$name = $method->getName();
if ($name !== 'actions' && $method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0) {
$actions[] = Inflector::camel2id(substr($name, 6), '-', true);
}
}
sort($actions);
return array_unique($actions);
}
示例3: redirectWithMessages
/**
* @param $flag
* @param $successMessage
* @param $failedMessage
*
* @return \yii\web\Response
*/
protected function redirectWithMessages($flag, $successMessage, $failedMessage)
{
if ($flag) {
Yii::$app->session->setFlash('success', $successMessage);
return $this->controller->redirect($this->successUrl);
} else {
Yii::$app->session->setFlash('warning', $failedMessage);
return $this->controller->redirect($this->failedUrl);
}
}
示例4: init
public function init()
{
parent::init();
$model = new Category();
$map = ['status' => 1];
$model->getList($map);
}
示例5: beforeAction
public function beforeAction($action)
{
if ($action->id === 'result' || $action->id === 'success' || $action->id === 'fail') {
$this->enableCsrfValidation = false;
}
return parent::beforeAction($action);
}
示例6: actions
/**
* @inheritdoc
*/
public function actions()
{
$actions = parent::actions();
$actions['login'] = ['class' => LoginAction::className(), 'modelClass' => $this->modelClass];
$actions['logout'] = ['class' => LogoutAction::className()];
return $actions;
}
示例7: beforeAction
public function beforeAction($action)
{
if ($action->id == 'index' && Yii::$app->request->referrer !== null) {
Yii::$app->session->set('returnUrl', Yii::$app->request->referrer);
}
return parent::beforeAction($action);
}
示例8: beforeAction
public function beforeAction($action)
{
if (in_array($action->id, $this->needAuthActions)) {
$this->layout = 'controlpanel';
}
return parent::beforeAction($action);
}
示例9: beforeAction
/**
* @inheritdoc
*/
public function beforeAction($action)
{
if (Yii::$app->user->isGuest) {
return false;
}
return parent::beforeAction($action);
}
示例10: behaviors
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['accessControl'] = $this->accessControlBehavior();
$behaviors['accessControl']['rules'] = array_merge([['allow' => true, 'actions' => ['grid-view-settings', 'route-to-url'], 'roles' => ['@']]], $behaviors['accessControl']['rules']);
return $behaviors;
}
示例11: beforeAction
/**
* @inheritdoc
*
* @param \yii\base\Action $action
* @return bool|\yii\web\Response
* @throws \yii\web\BadRequestHttpException
*/
public function beforeAction($action)
{
if (Yii::$app->user->isGuest) {
return $this->redirect(['/passport/account/login']);
}
return parent::beforeAction($action);
}
示例12: init
public function init()
{
parent::init();
$n_sr = false;
$n_ar = false;
$n_s = false;
$n_a = false;
//poka 4to zdes' delaem zada4i controllera no porom nado srochno pereexat'
if (!Yii::$app->user->isGuest) {
if (Yii::$app->user->identity->getStageReportNotification()) {
$n_sr = Yii::$app->user->identity->getStageReportNotification();
}
if (Yii::$app->user->identity->getAssignmentReportNotification()) {
$n_ar = Yii::$app->user->identity->getAssignmentReportNotification();
}
if (Yii::$app->user->identity->getStageNotification()) {
$n_s = Yii::$app->user->identity->getStageNotification();
}
if (Yii::$app->user->identity->getAssignmentNotification()) {
$n_a = Yii::$app->user->identity->getAssignmentNotification();
}
}
Yii::$app->view->params['n_sr'] = $n_sr;
Yii::$app->view->params['n_ar'] = $n_ar;
Yii::$app->view->params['n_s'] = $n_s;
Yii::$app->view->params['n_a'] = $n_a;
}
示例13: render
/**
* If we are acting in the module context and the layout is empty we only should renderPartial the content.
*
* @param string $view The name of the view file (e.g. index)
* @param array $params The params to assign into the value for key is the variable and value the content.
*
* @return string
*/
public function render($view, $params = [])
{
if (!empty($this->module->context) && empty($this->layout)) {
return $this->renderPartial($view, $params);
}
return parent::render($view, $params);
}
示例14: beforeAction
/**
* @inheritdoc
*/
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$excludeActions = $this->excludeActions();
if (in_array($action->id, $excludeActions)) {
return true;
}
if ($this->user->isGuest) {
throw new UnauthorizedHttpException();
}
if ($this->id == 'site') {
return true;
}
/* @var $identity \app\models\admin */
$identity = $this->user->identity;
if ($identity->admin_role_id == 1) {
return true;
}
$acls = $identity->adminRole->acls;
$define = static::acls();
if (isset($acls[$this->id])) {
foreach ($acls[$this->id] as $rule => $true) {
if (isset($define[$rule]) && isset($define[$rule]['actions']) && in_array($action->id, $define[$rule]['actions'])) {
return true;
}
}
}
throw new ForbiddenHttpException();
}
return true;
}
示例15: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (empty($this->modelTitleForms)) {
$this->modelTitleForms = PhpMorphy::getNeededForms($this->modelTitle);
}
}