php - CodeIgniter View 不解析 PHP

标签 php codeigniter

我已经或多或少地安装并正确运行了 CodeIgniter。我的应用程序正在加载 Controller 并显示 View 。

但是,如果使用短标签 <?=base_url()?>和我以前一样,这个版本不会将它们解析为 PHP。

我应该包含完整标签吗 <?php echo base_url(); ?>执行在第一个 PHP 标记处立即停止。

PHP 必须在某个时候被解析,因为当使用短标签时, Controller 仍然可以正确加载,但生成的 HTML 带有未解析的短标签。可能是什么问题?

    <div id="container">
    <div id="content">
        <img src="<?=base_url() . 'assets/images/cool_critter_logo_trans.png'?>" 
            alt="Cool Critters Logo" id="logo_image" />
        <h1>Welcome to Cool Critters!</h1>

        <p>
            This website is undergoing some serious updates! Please be patient as we work behind the scenes
            to improve the functionality and look of the website!
        </p>

        <p>
            Cool Critters is your source for dog training and agility supplies, courses, and information.
        </p>

        <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
    </div>
    </div>

这在另一台服务器上的先前迭代中有效,我在移动中破坏了一些东西。

可在此处获取:http://107.21.96.179:81/

最佳答案

我的猜测是您的服务器不允许使用短标签。您可以更改配置文件中的设置,以允许 CI 即时重写短标签。

从第 372 行开始看:https://github.com/EllisLab/CodeIgniter/blob/develop/application/config/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;

和文档: http://codeigniter.com/user_guide/general/alternative_php.html

关于php - CodeIgniter View 不解析 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8827377/

相关文章:

PHP - 检查值不会在数组中出现两次

php - 如何将动态网址变成静态网址

php - Mysql 查询执行时间过长

php - 在 LEFT JOIN PHP MySQL CodeIgniter 中选择最新行

php - 在 CodeIgniter 上添加 URL 变量

php - 使用 codeigniter 删除数据库记录

php - Codeigniter - if 语句中的正则表达式?

php - Amazon PHP SDK 最小文件

php - WAMPSERVER - 仅将 PHP 版本从 5.4.3 升级到 5.5.4

php - 如何将发布数据放入 CodeIgniter 中的数组中?帖子项目是数组