繁体   English   中英

CodeIgniter视图无法解析PHP

[英]CodeIgniter Views not parsing PHP

我已经安装并正确运行CodeIgniter,或多或少。 我的应用程序正在加载控制器并显示视图。

但是,如果像以前一样使用短标记<?=base_url()?> ,则此版本不会将它们解析为PHP。

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

必须在某些时候解析PHP,因为在使用短标记时,控制器仍然可以正确加载,但会生成带有未解析的短标记的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.17981 /

我的猜测是你的服务器不允许使用短标签。 您可以更改配置文件中的设置,以允许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

Just Roel说,如果你不加载帮助器, base_url()函数不起作用。

在控制器的构造函数中添加辅助加载器

 $this->load->helper('url');

这绝对不是Codeigniter的问题。 我在我的视图中使用短标记没有任何问题。

Codeigniter不像Django或Ruby那样“解析”视图。 代码作为标准php执行。

你确定你没有在PHP配置中禁用短标签吗? 我敢打赌这就是问题所在。 如果没有,您可能没有使用正确的语法。

有些服务器不支持所谓的短标签,因此建议您完全写出来。 除此之外,您必须加载URL帮助程序才能在视图中使用base_url()

只需添加$this->load->helper('url'); 到构造函数或加载模型等的地方

Codeigniter可以动态重写短标签。 在application / config / config.php中查找“重写短标签”

无论CodeIgniter中的设置如何,PHP都需要允许短标签。

在php.ini中,设置:

short_open_tag=On

重启apache。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM