Yii 1.1.16 - renderPartial () adds a space at the start of output

Is it just me, or renderPartial() add extra space before exiting it? This seems to be happening with all of my renderPartial() . render() works fine for me and doesn't add extra space.

here is a sample code. Trying to create RSS and get error due to 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 space in front of <?xml>

if I empty my feed.php and just put

 <span>asadadasfaf</span> 

there will still be space in front of the <span>

I use this extension to generate RSS https://github.com/2amigos/efeed

Firefox gives me this error because of a space

 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 use:

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

Does anyone know about work? or with the same problems?

+5
source share
2 answers

Found a problem, I had a place in front of the <?php tag in the controller causing the action.: \

+1
source

I do not know exactly why renderPartial() adds extra space, but you can do something like this.

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

Since render() works for you, and with $this->layout='' you can turn off the rendering layout for viewing.

Hope this works for you.

0
source

Source: https://habr.com/ru/post/1212765/


All Articles