Yii Tutorials

MVC aims to separate business logic from user interface considerations, so that developers can more easily change each part without affecting the other. In MVC, the model represents the information (the data) and the business rules; the view contains elements of the user interface such as text, form inputs; and the controller manages the communication between the model and the view. Besides implementing MVC, Yii also introduces a front-controller, called Application, which encapsulates the execution context for the processing of a request.

Application collects some information about a user request and then dispatches it to an appropriate controller for further handling.

Yii Data Modeling

Follow the conventions and one can create sophisticated Yii applications without writing and managing complex configurations. Of course, Yii can still be customized in nearly every aspect with configurations when needed. Below we describe conventions that are recommended for Yii programming. For convenience, we assume that WebRoot is the directory that a Yii application is installed at. By default, Yii recognizes URLs with the following format: The r GET variable refers to the route that can be resolved by Yii into controller and action. With the help of CUrlManager, it is possible to create and recognize more SEO-friendly URLs, such as This feature is covered in detail in URL Management. 2. Yii recommends naming variables, functions and class types in camel case which capitalizes the first letter of each word in the name and joins them without spaces.

Application. The application object encapsulates the execution context within which a request is processed.

Its main task is to collect some basic information about the request, and dispatch it to an appropriate controller for further processing. It also serves as the central place for keeping application-level configuration settings.
CApplication. Look up a class, method, property or event CApplication is the base class for all application classes.

An application serves as the global context that the user request is being processed. It manages a set of application components that provide specific functionalities to the whole application. The core application components provided by CApplication are the following: errorHandler: handles PHP errors and uncaught exceptions. CApplication will undergo the following lifecycles when processing a user request: load application configuration;set up class autoloader and error handling;load static application components;onBeginRequest: preprocess the user request;processRequest: process the user request;onEndRequest: postprocess the user request; Starting from lifecycle 3, if a PHP error or an uncaught exception occurs, the application will switch to its error handling logic and jump to step 6 afterwards.

Events Hide inherited events Property Details. CComponent. Look up a class, method, property or event CComponent is the base class for all components.

CComponent implements the protocol of defining, using properties and events. A property is defined by a getter method, and/or a setter method. Properties can be accessed in the way like accessing normal object members. Reading or writing a property will cause the invocation of the corresponding getter or setter method, e.g $a=$component->text; // equivalent to $a=$component->getText(); $component->text='abc'; // equivalent to $component->setText('abc'); The signatures of getter and setter methods are as follows, // getter, defines a readable property 'text' public function getText() { ... } // setter, defines a writable property 'text' with $value to be set to the property public function setText($value) { ... } An event is defined by the presence of a method whose name starts with 'on'. Function eventHandler($event) { ... }
Yii Class Reference. YiiBase. Look up a class, method, property or event YiiBase is a helper class serving common framework functionalities.

Do not use YiiBase directly. Instead, use its child class Yii where you can customize methods of YiiBase. Property Details public static array $classMap; class map used by the Yii autoloading mechanism. Public static boolean $enableIncludePath; whether to rely on PHP include path to autoload class files. Method Details. Yii. Resources. Yii is a popular framework with a vibrant and active community.

Below are some additional resources contributed by our community members that you may find useful. Cheat Sheets The Yii cheat sheet, created by Sebastián Thierer. This presents commonly used Yii classes, methods and properties in a single printable sheet.
Yii-1.0-cheatsheet.pdf (application/pdf Object)