www.state-it.info

Gran base de respuestas a las preguntas de los desarrolladores
Header decor

Error de syntax error, unexpected 'if' (T_IF), expecting ']'?

swallow_97 2018-06-05 17:28:06

ayuda por favor con el 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()


No veo correctamente colocadas entre corchetes.

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                     ]);?>

Total answers: 2

iSensetivity 2018-06-05 17:30:41

95 la línea en el ejemplo, debe бьіть ]);

Y aún, en lugar de las construcciones de tipo:

Yii::$app->user->isGuest ? '': 
                             [
                                 'label' => 'Партнёрам',
                                 'url' => ['/partner/index'],
                                 'options' => ['class' => 'menu-item']
                             ],


puede ser:
[
  'label' => 'Партнёрам',
  'url' => ['/partner/index'],
  'options' => ['class' => 'menu-item'],
  'visible' => !Yii::$app->user->isGuest
],

swallow_97 2018-06-05 17:34:08

muchas Gracias


Sanasol 2018-06-05 17:30:43

no veo correctamente colocadas entre corchetes.

bueno, entonces marque la IDE o un bloc de notas con подстветкой al menos.

Preguntas relacionadas:

Footer decor

© www.state-it.info | Base of answers to questions for developers and programmers.