【问题标题】:How do you enable short-tag syntax in codeigniter?如何在 codeigniter 中启用短标签语法?
【发布时间】:2012-07-18 01:01:15
【问题描述】:

我有一个应用程序(CodeIgniter)使用

<?=$variable?>

语法而不是

<?php echo $variable; ?>

我想让它在我的本地主机上工作。我需要在我的 php.ini 文件中启用什么来执行此操作?

请注意,我问的不是如何启用 short_open_tag,而是如何在 CodeIgniter 中启用它。

提前谢谢..

【问题讨论】:

  • 真正的 RTFM:“注意:该指令还影响 PHP 5.4 之前的 &lt;?= 简写。”。 -1 表示没有实际阅读。

标签: php codeigniter syntax codeigniter-2


【解决方案1】:

在 CodeIgniter 的config.php:

/*
|--------------------------------------------------------------------------
| Rewrite PHP Short Tags
|--------------------------------------------------------------------------
|
| If your PHP installation does not have short tag support enabled CI
| can rewrite the tags on-the-fly, enabling you to utilize that syntax
| in your view files.  Options are TRUE or FALSE (boolean)
|
*/
$config['rewrite_short_tags'] = FALSE;

这也意味着它不依赖于主机。

【讨论】:

    【解决方案2】:

    【讨论】:

    • 谢谢。这很有趣。
    【解决方案3】:
    1. 在你的php安装目录中搜索php.ini文件
    2. 用任何文本编辑器打开它,然后再次搜索“short_open_tag”,如果您找到类似“;short_open_tag = Off”的行,然后删除“;”并重新启动您的 apache 服务器它将工作。但我强烈要求您不要使用 php 短标签,因为并非所有 Web 服务器都接受 php 短标签。

    【讨论】:

      【解决方案4】:

      最好在服务器上启用短格式标签。这会阻止 CodeIgniter 重写你的标签。

      在 PHP 安装目录中找到您的 PHP.ini 文件。搜索“short_open_tag”。您将在“语言选项”下看到它被多次引用。找到未注释的并将其更改为 on。

      INI 如下所示:

      ;;;;;;;;;;;;;;;;;;;;
      ; Language Options ;
      ;;;;;;;;;;;;;;;;;;;;
      
      ; Enable the PHP scripting language engine under Apache.
      ; http://php.net/engine
      engine = On
      
      ; This directive determines whether or not PHP will recognize code between
      ; <? and ?> tags as PHP source which should be processed as such. It's been
      ; recommended for several years that you not use the short tag "short cut" and
      ; instead to use the full <?php and ?> tag combination. With the wide spread use
      ; of XML and use of these tags by other languages, the server can become easily
      ; confused and end up parsing the wrong code in the wrong context. But because
      ; this short cut has been a feature for such a long time, it's currently still
      ; supported for backwards compatibility, but we recommend you don't use them.
      ; Default Value: On
      ; Development Value: Off
      ; Production Value: Off
      ; http://php.net/short-open-tag
      ;short_open_tag = Off
      ; XAMPP for Linux is currently old fashioned
       short_open_tag = On
      

      【讨论】:

        猜你喜欢
        • 2013-01-29
        • 2011-01-12
        • 2020-04-28
        • 2015-09-21
        • 2013-03-29
        • 1970-01-01
        • 2013-10-07
        • 2015-12-30
        • 1970-01-01
        相关资源
        最近更新 更多