Package | system.web |
---|---|
Inheritance | class CController » CBaseController » CComponent |
Subclasses | CCodeGenerator, CExtController |
Since | 1.0 |
Source Code | framework/web/CController.php |
CController manages a set of actions which deal with the corresponding user requests.
Through the actions, CController coordinates the data flow between models and views.
When a user requests an action 'XYZ', CController will do one of the following: 1. Method-based action: call method 'actionXYZ' if it exists; 2. Class-based action: create an instance of class 'XYZ' if the class is found in the action class map (specified via actions(), and execute the action; 3. Call missingAction(), which by default will raise a 404 HTTP exception.
If the user does not specify an action, CController will run the action specified by defaultAction, instead.
CController may be configured to execute filters before and after running actions. Filters preprocess/postprocess the user request/response and may quit executing actions if needed. They are executed in the order they are specified. If during the execution, any of the filters returns true, the rest filters and the action will no longer get executed.
Filters can be individual objects, or methods defined in the controller class. They are specified by overriding filters() method. The following is an example of the filter specification:
array( 'accessControl - login', 'ajaxOnly + search', array( 'COutputCache + list', 'duration'=>300, ), )
The above example declares three filters: accessControl, ajaxOnly, COutputCache. The first two are method-based filters (defined in CController), which refer to filtering methods in the controller class; while the last refers to an object-based filter whose class is 'system.web.widgets.COutputCache' and the 'duration' property is initialized as 300 (s).
For method-based filters, a method named 'filterXYZ($filterChain)' in the controller class will be executed, where 'XYZ' stands for the filter name as specified in filters(). Note, inside the filter method, you must call $filterChain->run() if the action should be executed. Otherwise, the filtering process would stop at this filter.
Filters can be specified so that they are executed only when running certain actions. For method-based filters, this is done by using '+' and '-' operators in the filter specification. The '+' operator means the filter runs only when the specified actions are requested; while the '-' operator means the filter runs only when the requested action is not among those actions. For object-based filters, the '+' and '-' operators are following the class name.
Hide inherited properties
Property | Type | Description | Defined By |
---|---|---|---|
action | CAction | the action currently being executed, null if no active action. | CController |
actionParams | array | Returns the request parameters that will be used for action parameter binding. | CController |
cachingStack | CStack | stack of COutputCache objects | CController |
clips | CMap |
Returns the list of clips. |
CController |
defaultAction | string | the name of the default action. | CController |
id |
string |
ID of the controller | CController |
layout |
mixed |
the name of the layout to be applied to this controller's views. | CController |
module |
CWebModule |
the module that this controller belongs to. | CController |
pageTitle |
string |
the page title. | CController |
route |
string |
the route (module ID, controller ID and action ID) of the current request. | CController |
uniqueId |
string |
the controller ID that is prefixed with the module ID (if any). | CController |
viewPath |
string |
Returns the directory containing view files for this controller. | CController |