如何在codeigniter中启用短标签语法?

时间:2012-07-18 01:01:16

标签: php codeigniter syntax codeigniter-2

我有一个使用

的应用程序(CodeIgniter)
<?=$variable?>

语法而不是

<?php echo $variable; ?>

我希望它可以在我的本地主机上运行。我需要在php.ini文件中启用它来执行此操作是什么?

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

提前致谢..

4 个答案:

答案 0 :(得分:5)

在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;

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

答案 1 :(得分:3)

答案 2 :(得分:3)

  1. 在php安装目录中搜索php.ini文件
  2. 通过任何文本编辑器打开它然后只是你再次搜索“short_open_tag”如果你找到像“; short_open_tag = Off”这样的行然后只删除“;”并重新启动您的Apache服务器它将工作。但我强烈要求你不要使用php短标签,因为并非所有的web服务器都接受php短标签。

答案 3 :(得分:0)

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

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

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