Answer the question
In order to leave comments, you need to log in
Error syntax error, unexpected 'if' (T_IF), expecting ']'?
please help me with this error:
syntax error, unexpected 'if' (T_IF), expecting ']'
1. in /var/www/u0498223/public_html/coinfactory.pw/views/layouts/main.php at line 75
66 'url' => ['/cabinet/index'],
67 'options' => ['class' => 'menu-item']
68 ],
69 Yii::$app->user->isGuest ? '':
70 [
71 'label' => 'Партнёрам',
72 'url' => ['/partner/index'],
73 'options' => ['class' => 'menu-item']
74 ],
75 if (Yii::$app->user->isGuest):
76 [
77 'label' => 'Регистрация',
78 'url' => ['/user/reg'],
79 'options' => ['class' => 'menu-item']
80 ],
81 [
82 'label' => 'Войти',
83 'url' => ['/user/login'],
84 'options' => ['class' => 'menu-item']
2. yii\base\ErrorHandler::handleFatalError()
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 [
49 'label' => 'Главная',
50 'url' => ['/site/index'],
51 'options' => ['class' => 'menu-item']
52 ],
53 [
54 'label' => 'О Нас',
55 'url' => ['/site/about'],
56 'options' => ['class' => 'menu-item']
57 ],
58 [
59 'label' => 'Контакты',
60 'url' => ['/site/contact'],
61 'options' => ['class' => 'menu-item']
62 ],
63 Yii::$app->user->isGuest ? '':
64 [
65 'label' => 'Кабинет',
66 'url' => ['/cabinet/index'],
67 'options' => ['class' => 'menu-item']
68 ],
69 Yii::$app->user->isGuest ? '':
70 [
71 'label' => 'Партнёрам',
72 'url' => ['/partner/index'],
73 'options' => ['class' => 'menu-item']
74 ],
75 if (Yii::$app->user->isGuest):
76 [
77 'label' => 'Регистрация',
78 'url' => ['/user/reg'],
79 'options' => ['class' => 'menu-item']
80 ],
81 [
82 'label' => 'Войти',
83 'url' => ['/user/login'],
84 'options' => ['class' => 'menu-item']
85 ],
86 else:
87 [
88 'label' => 'Выйти ('.Yii::$app->user->identity['username'].')',
89 'url' => ['/user/logout'],
90 'template' => '<a href="{url}", data-method="post">{label}</a>',
91 'options' => ['class' => 'menu-item',],
92 'linkOptions' => ['data-method' => 'post']
93 ],
94 endif;
95 )];
96 echo Menu::widget([
97 'items' => $menuItems,
98 'options' => ['class' => 'reset', 'role' => 'navigation'],
99
100 ]);?>
Answer the question
In order to leave comments, you need to log in
Line 95 in the example should be ]);
Also, instead of constructs like:
Yii::$app->user->isGuest ? '':
[
'label' => 'Партнёрам',
'url' => ['/partner/index'],
'options' => ['class' => 'menu-item']
],
[
'label' => 'Партнёрам',
'url' => ['/partner/index'],
'options' => ['class' => 'menu-item'],
'visible' => !Yii::$app->user->isGuest
],
I don't see any misplaced parentheses.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question