Когда напрямую в экшене пишу
Код: Выделить всё
public function actionCreate()
{
if (Yii::$app->user->isGuest)
{
return $this->redirect(['./../../']); //ЗДЕСЬ
}
$model = new Companies();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Event::on(User::class, User::EVENT_ACT_USER, [$this, 'getEvent']);
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
Когда функцию использую
Код: Выделить всё
public function checkAccess(){
if (Yii::$app->user->isGuest)
{
return $this->redirect(['./../../']);
}
}
public function actionCreate()
{
$this->checkAccess(); //ЗДЕСЬ
$model = new Companies();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Event::on(User::class, User::EVENT_ACT_USER, [$this, 'getEvent']);
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
Код: Выделить всё
Trying to get property of non-object
1. in /Users/svetlanailina/Sites/boxic/backend/views/layouts/cp.php at line 48
39404142434445464748495051525354555657 'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems[] = ['label' => 'Главная', 'url' => ['/../../']];
$menuItems[] = '<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Выход (' . Yii::$app->user->identity->surname . ')', //ЗДЕСЬ
['class' => 'btn btn-link logout']
)
. Html::endForm()
. '</li>';
echo Nav::widget([
'options' => ['cl