本文介绍了如何检查主布局中是否定义了常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主布局文件中有以下代码片段(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 } ?>

但是我收到此错误,但我不知道为什么:

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

您按下了ALT-GR + SPACE组合键,您的编辑器将其显示为正常空间,但实际上是PHP无法解码的特殊字符. /p>

这通常发生在意大利语键盘上,其中"{"用ALT-GR + SHIFT + [印刷.当您真正快速键入内容时(就像优秀的程序员一样:),您会这样

  1. 几乎同时按下Shift和ALT-GR
  2. 按[
  3. 发布[
  4. 发布ALT-GR和SHIFT
  5. 按空格键

有时,第4步和第5步被切换,您得到了未知的角色.

删除IF语句中的所有空格,然后重试,它将被修复(然后正确重新设置空格!)

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:

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

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!)

这篇关于如何检查主布局中是否定义了常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 09:16