作者:simplato
项目:staf
/**
* @param \yii\base\Action $action
*/
public function beforeAction($action)
{
if ($action->controller->id == 'default') {
\yii\web\Controller::redirect('/staff/admin');
}
return true;
}
作者:songhongy
项目:datecente
/**
* 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);
}
作者:ufocode
项目:yii2-syncsocia
/**
* @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);
}
}
作者:xiaoneng198
项目:lear
public function init()
{
parent::init();
$model = new Category();
$map = ['status' => 1];
$model->getList($map);
}
作者:anderp
项目:7hours.yii.lo
public function beforeAction($action)
{
if ($action->id === 'result' || $action->id === 'success' || $action->id === 'fail') {
$this->enableCsrfValidation = false;
}
return parent::beforeAction($action);
}
作者:voskobovic
项目:yii2-auth-toolki
/**
* @inheritdoc
*/
public function actions()
{
$actions = parent::actions();
$actions['login'] = ['class' => LoginAction::className(), 'modelClass' => $this->modelClass];
$actions['logout'] = ['class' => LogoutAction::className()];
return $actions;
}
作者:sankam-nikoly
项目:yii2-user
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);
}
作者:kintastis
项目:mobil_ol
public function beforeAction($action)
{
if (in_array($action->id, $this->needAuthActions)) {
$this->layout = 'controlpanel';
}
return parent::beforeAction($action);
}
作者:jhlilian
项目:dongdong-gym-admi
/**
* @inheritdoc
*/
public function beforeAction($action)
{
if (Yii::$app->user->isGuest) {
return false;
}
return parent::beforeAction($action);
}
作者:omniligh
项目:yz2-admi
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;
}
作者:jhlilian
项目:dongdong-gym-admi
/**
* @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);
}
作者:Sheriye
项目:G5-CR
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;
}
作者:krystian-thied
项目:luy
/**
* 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);
}
作者:mole-or
项目:yii2-admi
/**
* @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;
}
作者:e9
项目:yii2-madmi
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (empty($this->modelTitleForms)) {
$this->modelTitleForms = PhpMorphy::getNeededForms($this->modelTitle);
}
}
作者:jacco
项目:wrkmtspr_pr
public function init()
{
//check for abonnement permission
$user = Yii::$app->getModule("user")->model("User");
if (($user = $user::findOne(Yii::$app->user->userid)) !== null) {
if ($user->abonnement->active == 0) {
throw new ForbiddenHttpException('
<div class="text-center">
<h3>
<p class="bg-danger">
<br>Uw abonnement is (nog) niet actief of inmiddels verlopen!<br><br>
</p>
</h3>
<br><br>
</div>
<div class="text-center">
<a href="http://werkmetspoor.nl/index.php/contact/" class="btn btn-danger" role="button">Neem contact met ons op</a>
</div>
');
}
}
// indien igelogged maar geen contactpersoon
if (!empty(Yii::$app->user) && !Yii::$app->user->can("contactpersoon")) {
throw new ForbiddenHttpException('Geen toegang');
}
parent::init();
}
作者:funson8
项目:yii2-blo
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
//menu
$id = isset($_GET['id']) ? $_GET['id'] : 0;
$rootId = $id > 0 ? BlogCatalog::getRootCatalogId($id, BlogCatalog::find()->all()) : 0;
$allCatalog = BlogCatalog::findAll(['parent_id' => 0]);
foreach ($allCatalog as $catalog) {
$item = ['label' => $catalog->title, 'active' => $catalog->id == $rootId];
if ($catalog->redirect_url) {
// redirect to other site
$item['url'] = $catalog->redirect_url;
} else {
$item['url'] = Yii::$app->getUrlManager()->createUrl(['/blog/default/catalog/', 'id' => $catalog->id, 'surname' => $catalog->surname]);
}
if (!empty($item)) {
array_push($this->mainMenu, $item);
}
}
Yii::$app->params['mainMenu'] = $this->mainMenu;
return true;
// or false if needed
} else {
return false;
}
}
作者:zw
项目:yii2_restfu
public function findLayoutFile($view)
{
if ($this->layout === null && $this->ajaxLayout !== false && Yii::$app->getRequest()->getIsAjax()) {
$this->layout = $this->ajaxLayout;
}
return parent::findLayoutFile($view);
}
作者:DiegoRodriguezTandi
项目:MoisesVill
/**
* @inheritdoc
*/
public function afterAction($action, $result)
{
if ($this->_oldMailPath !== null) {
Yii::$app->getMailer()->setViewPath($this->_oldMailPath);
}
return parent::afterAction($action, $result);
}
作者:realph
项目:yii2-admi
public function init()
{
parent::init();
if (Yii::$app->user->identity->id != 1) {
die('Illegal operation');
}
}