Difference between #6 and #5 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 ...
Write new article
  • Written by: fsb
  • Updated by: Mike
  • Category: Others
  • Yii Version: 1.1
  • Votes: +20
  • Viewed: 8,076 times
  • Created on: Dec 7, 2011
  • Last updated: May 3, 2013
  • Tags: errors comedy