background preloader

Yii

Facebook Twitter

Yii PHP Framework. Look up a class, method, property or event CWidget is the base class for widgets.

Yii PHP Framework

A widget is a self-contained component that may generate presentation based on model data. It can be viewed as a micro-controller that embeds into the controller-managed views. Compared with controller, a widget has neither actions nor filters. Usage is described at CBaseController and CBaseController::widget. Public Properties Hide inherited properties Property Details public string $actionPrefix; the prefix to the IDs of the actions. Returns the controller that this widget belongs to. public string getId(boolean $autoGenerate=true)public void setId(string $value) Returns the ID of the widget or generates a new one if requested. Returns the owner/creator of this widget. public mixed $skin; Fundamentals: Path Alias and Namespace.

Yii uses path aliases extensively.

Fundamentals: Path Alias and Namespace

A path alias is associated with a directory or file path. It is specified in dot syntax, similar to that of widely adopted namespace format: RootAlias.path.to.target where RootAlias is the alias of some existing directory. By using YiiBase::getPathOfAlias(), an alias can be translated to its corresponding path. We can also use YiiBase::setPathOfAlias() to define new root path aliases. How to include Javascript, CSS. There are many methods that we can include javascript, css into your Yii App.

How to include Javascript, CSS

Today I will demonstrate three simple and helpul methods. A simple way to add js, css by editing config/main.php ¶ 'components'=>array( 'clientScript'=>array( 'packages'=>array( 'jquery'=>array( 'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1/', 'js'=>array('jquery.min.js'), ) ), ), ), Using getClientScript ¶ Usually, We add in block of code into Controller or layout of your theme You can also add scripts from controller action.

$baseUrl = Yii::app()->baseUrl; $cs = Yii::app()->getClientScript(); $cs->registerScriptFile($baseUrl.' Or shorter: Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.' Please notice the second parameter when you register the js file, it's the position of your script, when you set it CClientScript::POS_END, you let the HTML renders before the javascript is loaded. Include core js files of framework ¶ Portlets: 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.

Portlets: Creating User Menu 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. 1. We create the UserMenu class to represent the logic part of the user menu portlet.

The UserMenu class extends from the CPortlet class from the zii library. Tip: Notice that we have to explicitly include the CPortlet class by calling Yii::import() before we refer to it the first time. Yii PHP Framework. Starship / RestfullYii Makes quickly adding a RESTFul API to your Yii project easy.

Yii PHP Framework

RestfullYii provides full HTTP verb support (GET, PUT, POST, DELETE) for your resources, as well as the ability to offset, limit, sort, filter, etc… . You will also have the ability to read and manipulate related data with ease. RestfullYii has been lovingly rebuilt from the metal and is now 100% test covered! The new event based architecture allows for clean and unlimited customization. How it works ¶ RestfullYii adds a new set of RESTFul routes to your standard routes, but prepends '/api' . So if you apply RestfullYii to the 'WorkController' you will get the following new routes by default. [GET] (returns all works) [GET] (returns work with PK=1) [POST] (create new work) [PUT] (update work with PK=1) [DELETE] (delete work with PK=1) Requirements ¶ Special Topics: Theming and Skin. Theming is a systematic way of customizing the outlook of pages in a Web application.

Special Topics: Theming and Skin

By applying a new theme, the overall appearance of a Web application can be changed instantly and dramatically. In Yii, each theme is represented as a directory consisting of view files, layout files, and relevant resource files such as images, CSS files, JavaScript files, etc. The name of a theme is its directory name. All themes reside under the same directory WebRoot/themes. At any time, only one theme can be active. Tip: The default theme root directory WebRoot/themes can be configured to be a different one. Unofficial Yii API Documentation.