Difference between #7 and #6 of The Comedy of Errors

unchanged
Title
The Comedy of Errors
unchanged
Category
Others
unchanged
Tags
errors
changed
Content
Please join the party by adding your own favorite Yii programming errors. Be
sure to leave at least a hint at the correction.

The missing echo
----------------

In the view put:
~~~
[php]
<h1>Edit item: <?php $model->label; ?></h1>
~~~

Now spend your time debugging why $model->label has no value set.

The echo too much
-----------------
In the view put:
~~~
[php]
<h1>Edit item: <?php echo $this->widget('CWidget'); ?></h1>
~~~
"Object of class CWidget could not be converted to string." A widget
may not have an echo.



Rules for numbers
-----------------

In the model rules() method put:
~~~
[php]
    array('count', 'number', 'integerOnly'=>true),
~~~
then try
~~~
[php]
    array('count', 'numeric', 'integerOnly'=>true),
~~~
and only then look it up: 'numerical'.


Rules for enums
---------------

In the model rules() method put:
~~~
[php]
    array('format', 'range', 'in' => array('html', 'rss2', 'atom', 'json',
'xml')),
~~~
then later remind yourself that Yii is not SQL.


Rules for foreign keys
----------------------

In the model rules() method put:
~~~
[php]
    array('foreingKey', 'exists', 'className' => 'SomeModel', 'attributeName'
=> 'id'),
~~~
Sure we have 'exists' method for CActiveRecord model, but ...

Ending ?> tag in non-view
---------------------------------

Extend a base class or edit a config file (needs to be included before the
sessions starts) and leave a ?> at the ending with at least one trailing
white space character. Make sure output buffering is off. Cry manly tears while
trying to figure out why "Cannot modify header information - headers
already sent" spams your log files.
Write new article
  • Written by: fsb
  • Updated by: Mike
  • Category: Others
  • Yii Version: 1.1
  • Votes: +20
  • Viewed: 7,309 times
  • Created on: Dec 7, 2011
  • Last updated: May 3, 2013
  • Tags: errors comedy