Creating User Menu Portlet ========================== Based on the requirements analysis, we need three different portlets: the "user menu" portlet, the "tag cloud" portlet and the "recent comments" portlet. We will develop these portlets by extending the [CPortlet] widget provided by Yii. In this section, we will develop our first concrete portlet - the user menu portlet which displays a list of menu items that are only available to authenticated users. The menu contains four items: * Approve Comments: a hyperlink that leads to a list of comments pending approval; * Create New Post: a hyperlink that leads to the post creation page; * Manage Posts: a hyperlink that leads to the post management page; * Logout: a link button that would log out the current user. Creating `UserMenu` Class ------------------------- We create the `UserMenu` class to represent the logic part of the user menu portlet. The class is saved in the file `/wwwroot/blog/protected/components/UserMenu.php` which has the following content: ~~~ [php] Yii::import('zii.widgets.CPortlet'); class UserMenu extends CPortlet { public function init() { $this->title=CHtml::encode(Yii::app()->user->name); parent::init(); } protected function renderContent() { $this->render('userMenu'); } } ~~~ The `UserMenu` class extends from the `CPortlet` class from the `zii` library. It overrides both the `init()` method and the `renderContent()` method of `CPortlet`. The former sets the portlet title to be the name of the current user; the latter generates the portlet body content by rendering a view named `userMenu`. > Tip: Notice that we have to explicitly include the `CPortlet` class by calling `Yii::import()` before we refer to it the first time. This is because `CPortlet` is part of the `zii` project -- the official extension library for Yii. For performance consideration, classes in this project are not listed as core classes. Therefore, we have to import it before we use it the first time. Creating `userMenu` View ------------------------ Next, we create the `userMenu` view which is saved in the file `/wwwroot/blog/protected/components/views/userMenu.php`: ~~~ [php]