【问题标题】:ErrorException [ Parse Error ]: syntax error, unexpected T_ENDIF [closed]ErrorException [ Parse Error ]:语法错误,意外的 T_ENDIF [关闭]
【发布时间】:2014-03-10 10:12:04
【问题描述】:

如果数据库中存在某些值,我想验证或显示选中的单选按钮。请参考我的意见代码,

<input type="radio" name="bothadvandlor"  value="1" <?php if($advs->is_checked == "1");?>checked="checked"<?php endif;?> class="advs"/> Show Google Ads<br/>
<input type="radio" name="bothadvandlor"  value="2" <?php if($advs->is_checked == "2");?>checked="checked"<?php endif;?> class="advs"/> Others

以上是我尝试过的形式,但我收到类似“ErrorException [ Parse Error ]: syntax error, unexpected T_ENDIF”的语法错误消息。

需要帮助来解决这个问题。

【问题讨论】:

    标签: php jquery kohana kohana-3


    【解决方案1】:

    应该是冒号:,

    if($advs->is_checked == "1"):
                                ^
    

    Reference.

    【讨论】:

      【解决方案2】:

      您需要在 if 条件之后使用冒号 : 而不是分号 ;

      if($advs->is_checked == "1"):
      // -----------------------  ^ here
      
      if($advs->is_checked == "2"):
      // -----------------------  ^ and here   
      

      来自docs

      PHP 为其某些控制结构提供了另一种语法; 即 if、while、for、foreach 和 switch。在每种情况下,基本 替代语法的形式是将左大括号更改为冒号 (:) 和结束大括号 endif;, endwhile;, endfor;, endforeach;, 或结束开关;分别。

      【讨论】:

        【解决方案3】:
        <input type="radio" name="bothadvandlor"  value="1" <?php if($advs->is_checked == "1"):?>checked="checked"<?php endif;?> class="advs"/> Show Google Ads<br/>
        <input type="radio" name="bothadvandlor"  value="2" <?php if($advs->is_checked == "2"):?>checked="checked"<?php endif;?> class="advs"/> Others
        

        【讨论】:

          【解决方案4】:

          我只是想补充一下 Kohana has got some neat stuff for this:

          公共静态收音机(字符串 $name [,字符串 $value = NULL,布尔 $checked = bool FALSE,数组 $attributes = NULL])

          例如

          <?php echo Form::radio('bothadvandlor', 1, ($advs->is_checked == '1'), array('class' => 'advs')); ?> Show Google Ads <br />
          

          我认为它使这类操作变得更加容易。更多的 HTML 和 PHP 分离从而更好的可读性。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2014-10-15
            • 2014-06-15
            • 2013-10-15
            • 2012-10-30
            • 1970-01-01
            • 2018-11-06
            • 2021-09-16
            • 2018-04-03
            相关资源
            最近更新 更多