duanping2695 2015-02-06 04:20
浏览 63

Yii 1.1.16 - renderPartial()在输出的开头添加一个空格

Is it just me, or does renderPartial() add an extra space in front of its output? It seems to do so with all my renderPartial()'s. render()works fine for me and doesn't add an extra space.

here is a sample code of mine. Trying to generate an RSS, and getting error's because of the extra space

public function actionFeed()
    {
        Yii::import('site.common.extensions.feed.*');

        $model = new ABC();

        $this->renderPartial('feed', array('model' => $model->findAll()));
    }

here is the generated html

 <?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel>

there is a space in front of <?xml>

if i empty my feed.php and just put

<span>asadadasfaf</span>

there would still be a space in front of <span>

I'm using this extension to generate the RSS https://github.com/2amigos/efeed

Because of the space, Firefox is giving me this error

XML Parsing Error: XML or text declaration not at start of entity
Location: http://localhost/dev/frontend/www/abc/feed/
Line Number 1, Column 2: <?xml version="1.0" encoding="utf-8"?>
-^

FYI, I'm using:

Yii 1.1.16
OSX 10.10.2
XAMPP 1.8.3-5
CHROME 40.0.2214.94 (64-bit) 
FIREFOX 35.0.1

Anyone know of a work around? or having the same issues?

  • 写回答

2条回答 默认 最新

  • doudong2149 2015-02-06 04:44
    关注

    I don't know exactly why renderPartial() is adding extra space there but you can do something like this.

    public function actionFeed()
        {
            $this->layout = '';
            $this->render('feed', array('model' => $model->findAll()));
        }
    

    Because render() is working for you and using using $this->layout='' you can disable rendering layout for view.

    Hope it'll work for you.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c