Please help with an error:

syntax error, unexpected 'if' (T_IF), expecting ']' 1. in /var/www/u0498223/public_html/coinfactory.pw/views/layouts/main.php at line 53 44 <? 45 $menuItems = array_filter([ 46 // Important: you need to specify url as 'controller/action', 47 // not just as 'controller' even if default action is used. 48 ['label' => 'Главная', 'url' => ['/site/index'], 'options' => ['class' => 'menu-item',]], 49 ['label' => 'О Нас', 'url' => ['/site/about'], 'options' => ['class' => 'menu-item',]], 50 ['label' => 'Контакты', 'url' => ['/site/contact'], 'options' => ['class' => 'menu-item',]], 51 Yii::$app->user->isGuest ? '': ['label' => 'Кабинет', 'url' => ['/cabinet/index'], 'options' => ['class' => 'menu-item',]], 52 Yii::$app->user->isGuest ? '': ['label' => 'Партнёрам', 'url' => ['/partner/index'], 'options' => ['class' => 'menu-item',]], 53 if (Yii::$app->user->isGuest): 54 ['label' => 'Регистрация', 'url' => ['/user/reg'], 'options' => ['class' => 'menu-item']]; 55 ['label' => 'Войти', 'url' => ['/user/login'], 'options' => ['class' => 'menu-item']]; 56 else: 57 ['label' => 'Выйти ('.Yii::$app->user->identity['username'].')', 58 'url' => ['/user/logout'], 59 'template' => '<a href="{url}", data-method="post">{label}</a>', 60 'options' => ['class' => 'menu-item',], 61 'linkOptions' => ['data-method' => 'post'] 62 ]; 2. yii\base\ErrorHandler::handleFatalError() 

I just don’t see incorrect brackets.

 44 <? 45 $menuItems = array_filter([ 46 // Important: you need to specify url as 'controller/action', 47 // not just as 'controller' even if default action is used. 48 ['label' => 'Главная', 'url' => ['/site/index'], 'options' => ['class' => 'menu-item',]], 49 ['label' => 'О Нас', 'url' => ['/site/about'], 'options' => ['class' => 'menu-item',]], 50 ['label' => 'Контакты', 'url' => ['/site/contact'], 'options' => ['class' => 'menu-item',]], 51 Yii::$app->user->isGuest ? '': ['label' => 'Кабинет', 'url' => ['/cabinet/index'], 'options' => ['class' => 'menu-item',]], 52 Yii::$app->user->isGuest ? '': ['label' => 'Партнёрам', 'url' => ['/partner/index'], 'options' => ['class' => 'menu-item',]], 53 if (Yii::$app->user->isGuest): 54 ['label' => 'Регистрация', 'url' => ['/user/reg'], 'options' => ['class' => 'menu-item']]; 55 ['label' => 'Войти', 'url' => ['/user/login'], 'options' => ['class' => 'menu-item']]; 56 else: 57 ['label' => 'Выйти ('.Yii::$app->user->identity['username'].')', 58 'url' => ['/user/logout'], 59 'template' => '<a href="{url}", data-method="post">{label}</a>', 60 'options' => ['class' => 'menu-item',], 61 'linkOptions' => ['data-method' => 'post'] 62 ]; 63 endif; 64 ]); 65 echo Menu::widget([ 66 'items' => $menuItems, 67 'options' => ['class' => 'reset', 'role' => 'navigation'], 68 69 ]); 70 ?> 
  • Of course, so write, you will not see anything - Naumov
  • @Naumov And what exactly did I write wrong? It seems that she wrote a special calculation to make it easier to understand (( - GaLana

1 answer 1

And if the code were formatted correctly, then everything would be visible

 $menuItems = array_filter([ // Important: you need to specify url as 'controller/action', // not just as 'controller' even if default action is used. $menuItems[] = [ 'label' => 'Главная', 'url' => ['/site/index'], 'options' => ['class' => 'menu-item',] ], $menuItems[] = [ 'label' => 'О Нас', 'url' => ['/site/about'], 'options' => ['class' => 'menu-item',] ], $menuItems[] = [ 'label' => 'Контакты', 'url' => ['/site/contact'], 'options' => ['class' => 'menu-item',] ], Yii::$app->user->isGuest ? '': $menuItems[] = [ 'label' => 'Кабинет', 'url' => ['/cabinet/index'], 'options' => ['class' => 'menu-item',] ], Yii::$app->user->isGuest ? '': $menuItems[] = [ 'label' => 'Партнёрам', 'url' => ['/partner/index'], 'options' => ['class' => 'menu-item',] ], // ???? где завершение array_filter([ if (Yii::$app->user->isGuest): $menuItems[] = [ 'label' => 'Регистрация', 'url' => ['/user/reg'], 'options' => ['class' => 'menu-item'] ]; $menuItems[] = [ 'label' => 'Войти', 'url' => ['/user/login'], 'options' => ['class' => 'menu-item'] ]; else: 

Well, the design

 $menuItems = array_filter([ $menuItems[] = [...], $menuItems[] = [...], .... 

Causes individual issues. What made you write like that?

  • and to finish it there, elements are put into the array and further - teran
  • @AntonShchyrov I don’t know)) for some reason I decided to write so .. but the problem is clearly not because of this ... And I finished the array_filter ([on line 69 .. so I don’t quite understand - GaLana 1:51 pm
  • one
    Well, who if inserts into the array as you imagine? - Naumov
  • @Naumov Thank you very much, corrected, the issue is resolved)) - GaLana
  • one
    @Naumov No one. On the contrary, I formatted the code and showed that before if you need to close the array and call the function - Anton Shchyrov