How to check if a constant is defined in main layout?

半城伤御伤魂 提交于 2019-12-13 05:16:46

问题


I've this snippet of code in main layout file (protected/views/layouts/main.php):

    <?php if (defined('YII_DEBUG')) { ?>
        <button id="search-hidden-button"></button>
        <script>
            $(function(){
                $('#search-hidden-button').click(function(){
                    $('#search-query-form').submit();
                });
            });
        </script>
    <?php } ?>

But I get this error and I dont know why:

Use of undefined constant - assumed ' '

    <?php if (true) { ?>
        <button id="search-hidden-button"></button>
        <script>
            $(function(){
                $('#search-hidden-button').click(function(){
                    $('#search-query-form').submit();
                });
            });
        </script>
    <?php } ?>

回答1:


You pressed a combination of ALT-GR + SPACE that your editor shows as a normal space but in fact is a special character that PHP can't decode.

This happens usually on Italian Keyboards, where "{" is printed with ALT-GR + SHIFT + [. When you type really fast (as good programmers do :) you do like this

  1. Press shift and ALT-GR almost at the same time
  2. Press [
  3. Release [
  4. Release ALT-GR and SHIFT
  5. Press Spacebar

Sometimes it happens that step 4 and 5 are switched, and you get your unknown character.

Remove all spaces in your IF statements and try again, it will be fixed (then re-space correctly!)




回答2:


No need defined again, try :

if(YII_DEBUG){}


来源:https://stackoverflow.com/questions/19157772/how-to-check-if-a-constant-is-defined-in-main-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!