New blog demo

I just created a blog demo using Yii (in SVN now). Please use this thread to report any problems you found with this demo. Thanks.

good,I'll have a try;…

Great to see a “real world” app created with Yii. I see it includes quite good amount of basic behaviors :) Here’s a few quick comments from me:

  1. Where’s the RSS feed? ;) What’s a blog without an RSS feed? Is there anything in Yii helping you providing feeds? I expect an RSS link in the head-tag and RSS link in the sidebar.

  2. Example of using themes. Nice if this demo also included just a few color variants or simply used a few popular blog themes. (WooThemes have some really nice new free themes now:

  3. Turn text "Remember me next time" into a label for the checkbox in login form so it's even easier to toggle the checkbox.

  1. Feed feature will be added in 1.0.2 or 1.0.3 release.

  2. Yes, this will be added very soon.

  3. Will do.

Thanks for your suggestions!

>I just created a blog demo using Yii (in SVN now). Please use this thread to >report any problems you found with this demo. Thanks.

I just found an error message as follows when I tried to create a new post using "create" button. Does anyone know the cause? I was not able to find such files as DOM*php anywhere. :cry:

PHP Error


YiiBase::include(DOMdocument.php) [<a href='yiibase.include'>yiibase.include</a>]: failed to open stream: No such file or directory

Source File


00280:      * Class autoload loader.

00281:      * This method is provided to be invoked within an __autoload() magic method.

00282:      * @param string class name

00283:      */

00284:    public static function autoload($className)

00285:    {

00286:        // use include so that the error PHP file may appear

00287:        if(isset(self::$_coreClasses[$className]))

00288:            include(YII_PATH.self::$_coreClasses[$className]);

00289:        else if(isset(self::$_classes[$className]))

00290:            include(self::$_classes[$className]);

00291:        else

00292: include($className.'.php');

00293:    }


00295:    /**

00296:      * Writes a trace message.

00297:      * This method will only log a message when the application is in debug mode.

00298:      * @param string message to be logged

00299:      * @param string category of the message

00300:      * @see log

00301:      */

00302:    public static function trace($msg,$category='application')

00303:    {

00304:        if(YII_DEBUG)

Make sure you have DOM php extension enabled (normally you should have it by default).


Make sure you have DOM php extension enabled (normally you should have it by default).

Thank you for helping me (and making such a nice demo)!

># yum install php-xml

saves me. :D

Thanks for this blog demo. As already suggested a fully featured demo with RSS etc would be great.

I'm trying to learn Yii right now and a 'finished' real world example I can de-construct and follow step-by-step is the key for me to get my head around it. I'm sure it's the same for others.

Many thanks for your amazing work and generosity in providing Yii. I'm determined to get up to speed as fast as possible.


Hi Qiang,

I have been studying yii by analysing this real-world blog demo. It is more effective to read the actual code than to read a thick manual of every language.

BTW, I made a small calendar widget for this blog demo in order to study the structure of the widget.

Those who would like to try it should do 'tar xvzf' to this attachment at the 'demos/blog' directory. Please be sure to download following source and rename it to 'blog/protected/components/views/generate_calendar.php'. As original source does not care much about multi-byte encoding scheme, and I have made several modifications to it, I eliminated it in the attachment.



Posted Image

Great work  ;)


ab -t 30 -c 10 */demos/blog/index.php/post/1

Why are relatively poor outcomes? (just 4.7 requests per seccond)



ab -t 30 -c 10 */demos/blog/

21.6 rps

Update: Later we found out that the problem was in my system

I guess that's because the comment form needs CAPTCHA?

Anyway, the blog demo has no optimization at all. For example, the AR schema should be cached and the portlets should be cached.

But when we compare "/demos/testdrive/" (63.0 rps) and "/demo/testdrive/index.php?r=site/contact" (44.9 rps) we can see that the establishment capcha took 0.0063 sec.

I just want to evaluate the performance Yii framework in real applications, and find bottlenecks.

I just did a quick test on my machine (Windows Vista):

without APC:

/demos/blog/                              27.88

/demos/blog/index.php/post/1        26.29

with APC:

/demos/blog/                              59.61

/demos/blog/index.php/post/1        55.64

Sorry. You are right the problem in my system.


ab -t 30 -c 10 /demos/blog/index.php/post/1

50%  - 2016

66%  - 2109

75%  - 2109

80%  - 2109

90%  - 2219

95%  - 2250

98%  - 2328

99%  - 2344

100% - 2344 (longest request)

one "bug" in the post\show.php

if comments are not approved they shouldn't been counted and displayed like "2 comments to …"

<?php if(count($comments)>=1): ?>


  <?php echo count($comments)>1 ? count($comments) . ' comments' : 'One comment'; ?>

should be

<?php if($post->commentCount>=1): ?>


  <?php echo $post->commentCount>1 ? $post->commentCount . ' comments' : 'One comment'; ?>

instead, so only approved comments are counted.

Also the comment or the post form should have some texts for guest users so they know that their submitted comment was submitted correctly and is waiting to be approved. Cause a redirect with #comment_id shows nothing because new anonymous comments are not approved and are therefore not displayed.

Thank you for your suggestions. Just updated the blog.

Just noticed that tags are not being properly updated while updating the post in demo blog.

After some debugging I found that the problem is in the afterSave() method of Post model. It tries to save the tags using the following code:

$tag=new Tag(array('name'=>$name));


Tags are saved with empty name, by some reason the attribute array are not properly applied. It works fine if I set the name directly like:

$tag=new Tag;

$tag->name = $name;


Did not investigate deeply yet, just want to know - am I the only one who have such behavior? Maybe the problems are on my side, not in the code?

Oops, as I can see the Post code has been already fixed in 530 revision. Sorry  :)

Im looking forward for the blog tutorial !!! please this is the best way to start with yii