dongxixian7803 2013-04-07 21:31
浏览 39
已采纳

Codeigniter php短标签不起作用

I'm currently following this basic Codeigniter tutorial and the author used this similar code in this view/post_index.php page

if (!isset($posts)){ ?>
    <p> No Post to display </p>
<?php
} else {
    foreach ($posts as $row){
?>
    <h2> <?=$row['title']?> </h2>
        <p> <?=$row['post'] ?></p>

<?php
    }
}
?>

and I get an empty page with this

<h2> <?=$row['title']?> </h2>
<p> <?=$row['post'] ?></p>

in my source.

However when I use this

    <h2> <?php echo $row['title']?> </h2>
    <p> <?php echo $row['post'] ?></p>

I'm fine. It shows all my posts. I'm running off wamp (just downloaded the 64bits & Apache 2.4, 2.2E Version off the website, except I don't see much difference with all the other 4 packages they have....) with Apache Version : 2.2.21
PHP Version : 5.3.10

What is going on?

Thank you.

  • 写回答

2条回答 默认 最新

  • duandui2803 2013-04-07 21:34
    关注

    That normally means you don't have short-tags enabled (most PHP < 5.4.0 installations turn them of by default). You'll need to check your php.ini file.

    Before you enable them, I would suggest reading https://softwareengineering.stackexchange.com/questions/151661/is-it-bad-practice-to-use-tag-in-php - there are pros and cons to using the short-tag syntax.

    @IMSoP also makes a very valid note:

    Specifically, you need the short_open_tag option (http://www.php.net/manual/en/ini.core.php#ini.short-open-tag) enabled if using PHP < 5.4. From 5.4 onwards, this setting is still present, but is not needed for the <?= ... ?> case, only the potentially problematic <? ... ?>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 数学建模数学建模需要
  • ¥15 c语言数据结构实验单链表的删除
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决