0 follower

Future Enhancements

1. Using a Theme

Without writing any code, our blog application is already themeable. To use a theme, we mainly need to develop the theme by writing customized view files in the theme. For example, to use a theme named classic that uses a different page layout, we would create a layout view file /wwwroot/blog/themes/classic/views/layouts/main.php. We also need to change the application configuration to indicate our choice of the classic theme:

return array(

2. Internationalization

We may also internationalize our blog application so that its pages can be displayed in different languages. This mainly involves efforts in two aspects.

First, we may create view files in different languages. For example, for the index page of PostController, we can create a view file /wwwroot/blog/protected/views/post/zh_cn/index.php. When the application is configured to use simplified Chinese (the language code is zh_cn), Yii will automatically use this new view file instead of the original one.

Second, we may create message translations for those messages generated by code. The message translations should be saved as files under the directory /wwwroot/blog/protected/messages. We also need to modify the code where we use text strings by enclosing them in the method call Yii::t().

For more details about internationalization, please refer to the Guide.

3. Improving Performance with Cache

While the Yii framework itself is very efficient, it is not necessarily true that an application written in Yii efficient. There are several places in our blog application that we can improve the performance. For example, the tag clould portlet could be one of the performance bottlenecks because it involves complex database query and PHP logic.

We can make use of the sophisticated caching feature provided by Yii to improve the performance. One of the most useful components in Yii is COutputCache, which caches a fragment of page display so that the underlying code generating the fragment does not need to be executed for every request. For example, in the layout file /wwwroot/blog/protected/views/layouts/column2.php, we can enclose the tag cloud portlet with COutputCache:

<?php if($this->beginCache('tagCloud', array('duration'=>3600))) { ?>
    <?php $this->widget('TagCloud', array(
    )); ?>
<?php $this->endCache(); } ?>

With the above code, the tag cloud display will be served from cache instead of being generated on-the-fly for every request. The cached content will remain valid in cache for 3600 seconds.

4. Adding New Features

Our blog application only has very basic functionalities. To become a complete blog system, more features are needed, for example, calendar portlet, email notifications, post categorization, archived post portlet, and so on. We will leave the implementation of these features to interested readers.

Found a typo or you think this page needs improvement?
Edit it on github !