Yii Framework Forum: Yii Echoing Extra Whitespace Into Templates? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Echoing Extra Whitespace Into Templates? When calling Model::model() for the first time Rate Topic: -----

#1 User is offline   mmitchell 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 02-October 13

Posted 03 October 2013 - 08:13 PM

Yii appears to be echoing out a single space character when I reference a model class for the first time, directly or indirectly. In most cases this doesn't matter (HTML is pretty liberal about whitespace), but in some cases it's sticking extra whitespace in the middle of some text, causing generated image files to error out, etc. Here's an anonymized version of one instance that's causing us trouble:

<li>My List ({$list->getItemCount()})</li>


(It's been awhile since I went down this particular rabbit hole but IIRC, calling getItemCount will result in the static model function getting called at some point.)

By itself, the result ends up looking like this:

  • My List ( 4)


After some slogging through the code, I couldn't find exactly where the space was being output, but I managed to find a pretty bewildering "fix":

{if User::model() && ListItem::model()}{/if}

...

<li>My List ({$list->getItemCount()})</li>


This shoves the whitespace in some part of the HTML I don't really care about, although it's not exactly pretty. However, there's no way to do this when outputting an image file, aside from even more gross hacks (redirect output when calling the model?) or avoiding the model() function entirely.

There's nothing in the User or ListItem model() functions that would cause this. They're both still in their Gii-generated form, where they return parent::model($className). I also tried removing the PHP closing tags, although there was no whitespace after them anyway. I looked around for a solution, but all I found was another user with a similar-seeming unresolved problem: http://www.yiiframew...er-closing-tag/

Am I missing something here? I'm using Yii 1.1 if that makes a difference.
0

#2 User is offline   mmitchell 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 02-October 13

Posted 04 October 2013 - 11:13 AM

Never mind, I am an idiot. ::) To any future Googlers having this problem, don't forget to check for whitespace before the opening PHP tags of the model, too.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users