Blog tutorial missing functions

The Customizing Post Model section of the Yii blog tutorial (and perhaps some that follow), use functions that have not been defined in the tutorial. For example, the custom normalizeTags validation rule calls the following functions:



Although the tutorial has not mentioned these, you can find copies of the functions in the blog demo sample code:


The sample Tag class also adds these functions:






I’ve created a Yii ticket, so hopefully the tutorial will be updated to reflect this.


well I’ve come in the blog tutorial until the customizing the post model ( so far. On creating a new post in the frontend I’ve got troubles on setting the tags. When I create a new post and add a tag list seperated with commata like this:

concert, music, electronic, band. It throws errors.

The string2array() method won’t work or I’ve overread something. But what’s wrong with this line?

return preg_split('/\s*,\s*/',trim($tags),-1,PREG_SPLIT_NO_EMPTY);

Nothing I think. Unfortunately I couldn’t find any solution in the demo blog classes. All methods the same… don’t know where to look now.

Finally, I solved it.

The line from above is korrekt as it is:

return preg_split('/\s*,\s*/',trim($tags),-1,PREG_SPLIT_NO_EMPTY);

In the Post.php, the post model, was the mistake. I forgot a comma in here:

array('tags', 'match', 'pattern'=>'/^[\w\s,]+$/','message'=>'Tags koennen nur aus Wortzeichen bestehen.'),

The commata in the pattern: /^[\w\s,]+$/

It was the rules() method from the post model.