You are viewing revision #4 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.
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:
<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:
<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:
array('count', 'number', 'integerOnly'=>true),
then try
array('count', 'numeric', 'integerOnly'=>true),
and only then look it up: 'numerical'.
Useful
Thanks! I was having one of these errors.
Semicolon error
That's why I tend to search/replace "\n{" in Yii-generated code and reformat it to have the curly brackets always in the end of the line :P
Semicolon error
@Igoru-san good point!
My IDE does that as part of reformatting to PSR-2, so I don't have to search-replace. (Also inserting a missing {} around the iterated instruction if necessary.)
It also highlights this error on the screen via it's static code inspections.
All in all, with a good IDE like PhpStorm, my code quality is better and I finish it faster.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.