Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • ActionFormModelBase
  • CActiveDataProvider
  • CalendarEventFormModel
  • CallFormModel
  • CArrayDataProvider
  • CAssetManager
  • CBaseController
  • CBaseUrlRule
  • CCacheHttpSession
  • CClientScript
  • CController
  • CCookieCollection
  • CDataProvider
  • CDataProviderIterator
  • CDbHttpSession
  • CExtController
  • CFormModel
  • CHttpCookie
  • CHttpRequest
  • CHttpSession
  • CHttpSessionIterator
  • COutputEvent
  • CPagination
  • CreatePageFormModel
  • CSort
  • CSqlDataProvider
  • CTheme
  • CThemeManager
  • CUploadedFile
  • CUrlManager
  • CUrlRule
  • CWebApplication
  • CWebModule
  • CWidgetFactory
  • EditMobileFormsFormModel
  • EventCommentPublisherFormModel
  • EventFormModel
  • EventPublisherFormModel
  • FileSystemObjectDataProvider
  • MassActionFormModel
  • MobilePagination
  • NoteFormModel
  • NotificationsController
  • TimeFormModel
  • UploadLogoFormModel
  • X2FormModel
  • X2HttpRequest

Interfaces

  • IDataProvider
  • IWidgetFactory
  • Overview
  • Package
  • Class
  • Tree

Class CController

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 CController::actions(), and execute the action;
  3. Call CController::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 CController::$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 CController::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 CController::filters(). Note, inside the filter method, you must call <span class="php-var">$filterChain</span>->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.

CComponent
Extended by CBaseController
Extended by CController

Direct known subclasses

Api2Controller, CExtController, NotificationsController, X2Controller

Indirect known subclasses

AccountsController, ActionsController, MediaController, MobileController, OpportunitiesController, ProductsController, ProfileController, QuotesController, RelationshipsController, SearchController, ServicesController, SiteController, AdminController, StudioController, TemplatesController, TopicsController, UsersController, WorkflowController, x2base, X2LeadsController, ApiController, BugReportsController, CalendarController, ContactsController, DocsController, GroupsController, MarketingController
Package: system\web
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/web/CController.php
Methods summary
public
# __construct( string $id, CWebModule $module = null )

Parameters

$id
string
$id id of this controller
$module
CWebModule
$module the module that this controller belongs to.
public
# init( )

Initializes the controller. This method is called by the application before the controller starts to execute. You may override this method to perform the needed initialization for the controller.

Initializes the controller. This method is called by the application before the controller starts to execute. You may override this method to perform the needed initialization for the controller.

public array
# filters( )

Returns the filter configurations.

Returns the filter configurations.

By overriding this method, child classes can specify filters to be applied to actions.

This method returns an array of filter specifications. Each array element specify a single filter.

For a method-based filter (called inline filter), it is specified as 'FilterName[ +|- Action1, Action2, ...]', where the '+' ('-') operators describe which actions should be (should not be) applied with the filter.

For a class-based filter, it is specified as an array like the following:

array(
    'FilterClass[ +|- Action1, Action2, ...]',
    'name1'=>'value1',
    'name2'=>'value2',
    ...
)

where the name-value pairs will be used to initialize the properties of the filter.

Note, in order to inherit filters defined in the parent class, a child class needs to merge the parent filters with child filters using functions like array_merge().

Returns

array
a list of filter configurations.

See

CFilter
public array
# actions( )

Returns a list of external action classes. Array keys are action IDs, and array values are the corresponding action class in dot syntax (e.g. 'edit'=>'application.controllers.article.EditArticle') or arrays representing the configuration of the actions, such as the following,

return array(
    'action1'=>'path.to.Action1Class',
    'action2'=>array(
        'class'=>'path.to.Action2Class',
        'property1'=>'value1',
        'property2'=>'value2',
    ),
);

Derived classes may override this method to declare external actions.

Returns a list of external action classes. Array keys are action IDs, and array values are the corresponding action class in dot syntax (e.g. 'edit'=>'application.controllers.article.EditArticle') or arrays representing the configuration of the actions, such as the following,

return array(
    'action1'=>'path.to.Action1Class',
    'action2'=>array(
        'class'=>'path.to.Action2Class',
        'property1'=>'value1',
        'property2'=>'value2',
    ),
);

Derived classes may override this method to declare external actions.

Note, in order to inherit actions defined in the parent class, a child class needs to merge the parent actions with child actions using functions like array_merge().

You may import actions from an action provider (such as a widget, see CWidget::actions()), like the following:

return array(
    ...other actions...
    // import actions declared in ProviderClass::actions()
    // the action IDs will be prefixed with 'pro.'
    'pro.'=>'path.to.ProviderClass',
    // similar as above except that the imported actions are
    // configured with the specified initial property values
    'pro2.'=>array(
        'class'=>'path.to.ProviderClass',
        'action1'=>array(
            'property1'=>'value1',
        ),
        'action2'=>array(
            'property2'=>'value2',
        ),
    ),
)

In the above, we differentiate action providers from other action declarations by the array keys. For action providers, the array keys must contain a dot. As a result, an action ID 'pro2.action1' will be resolved as the 'action1' action declared in the 'ProviderClass'.

Returns

array
list of external action classes

See

CController::createAction()
public array
# behaviors( )

Returns a list of behaviors that this controller should behave as. The return value should be an array of behavior configurations indexed by behavior names. Each behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName'=>array(
    'class'=>'path.to.BehaviorClass',
    'property1'=>'value1',
    'property2'=>'value2',
)

Returns a list of behaviors that this controller should behave as. The return value should be an array of behavior configurations indexed by behavior names. Each behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName'=>array(
    'class'=>'path.to.BehaviorClass',
    'property1'=>'value1',
    'property2'=>'value2',
)

Note, the behavior classes must implement IBehavior or extend from CBehavior. Behaviors declared in this method will be attached to the controller when it is instantiated.

For more details about behaviors, see CComponent.

Returns

array
the behavior configurations (behavior name=>behavior configuration)
public array
# accessRules( )

Returns the access rules for this controller. Override this method if you use the filterAccessControl accessControl filter.

Returns the access rules for this controller. Override this method if you use the filterAccessControl accessControl filter.

Returns

array
list of access rules. See CAccessControlFilter for details about rule specification.
public
# run( string $actionID )

Runs the named action. Filters specified via CController::filters() will be applied.

Runs the named action. Filters specified via CController::filters() will be applied.

Parameters

$actionID
string
$actionID action ID

Throws

CHttpException
if the action does not exist or the action name is not proper.

See

CController::filters()
CController::createAction()
CController::runAction()
public
# runActionWithFilters( CAction $action, array $filters )

Runs an action with the specified filters. A filter chain will be created based on the specified filters and the action will be executed then.

Runs an action with the specified filters. A filter chain will be created based on the specified filters and the action will be executed then.

Parameters

$action
CAction
$action the action to be executed.
$filters
array
$filters list of filters to be applied to the action.

See

CController::filters()
CController::createAction()
CController::runAction()
public
# runAction( CAction $action )

Runs the action after passing through all filters. This method is invoked by CController::runActionWithFilters() after all possible filters have been executed and the action starts to run.

Runs the action after passing through all filters. This method is invoked by CController::runActionWithFilters() after all possible filters have been executed and the action starts to run.

Parameters

$action
CAction
$action action to run
public array
# getActionParams( )

Returns the request parameters that will be used for action parameter binding. By default, this method will return $_GET. You may override this method if you want to use other request parameters (e.g. $_GET+$_POST).

Returns the request parameters that will be used for action parameter binding. By default, this method will return $_GET. You may override this method if you want to use other request parameters (e.g. $_GET+$_POST).

Returns

array
the request parameters to be used for action parameter binding

Since

1.1.7
public
# invalidActionParams( CAction $action )

This method is invoked when the request parameters do not satisfy the requirement of the specified action. The default implementation will throw a 400 HTTP exception.

This method is invoked when the request parameters do not satisfy the requirement of the specified action. The default implementation will throw a 400 HTTP exception.

Parameters

$action
CAction
$action the action being executed

Since

1.1.7
public string
# processOutput( string $output )

Postprocesses the output generated by CController::render(). This method is invoked at the end of CController::render() and CController::renderText(). If there are registered client scripts, this method will insert them into the output at appropriate places. If there are dynamic contents, they will also be inserted. This method may also save the persistent page states in hidden fields of stateful forms in the page.

Postprocesses the output generated by CController::render(). This method is invoked at the end of CController::render() and CController::renderText(). If there are registered client scripts, this method will insert them into the output at appropriate places. If there are dynamic contents, they will also be inserted. This method may also save the persistent page states in hidden fields of stateful forms in the page.

Parameters

$output
string
$output the output generated by the current action

Returns

string
the output that has been processed.
public string
# processDynamicOutput( string $output )

Postprocesses the dynamic output. This method is internally used. Do not call this method directly.

Postprocesses the dynamic output. This method is internally used. Do not call this method directly.

Parameters

$output
string
$output output to be processed

Returns

string
the processed output
protected string
# replaceDynamicOutput( array $matches )

Replaces the dynamic content placeholders with actual content. This is a callback function used internally.

Replaces the dynamic content placeholders with actual content. This is a callback function used internally.

Parameters

$matches
array
$matches matches

Returns

string
the replacement

See

CController::processOutput()
public CAction
# createAction( string $actionID )

Creates the action instance based on the action name. The action can be either an inline action or an object. The latter is created by looking up the action map specified in CController::actions().

Creates the action instance based on the action name. The action can be either an inline action or an object. The latter is created by looking up the action map specified in CController::actions().

Parameters

$actionID
string
$actionID ID of the action. If empty, the defaultAction default action will be used.

Returns

CAction
the action instance, null if the action does not exist.

See

CController::actions()
protected CAction
# createActionFromMap( array $actionMap, string $actionID, string $requestActionID, array $config = array() )

Creates the action instance based on the action map. This method will check to see if the action ID appears in the given action map. If so, the corresponding configuration will be used to create the action instance.

Creates the action instance based on the action map. This method will check to see if the action ID appears in the given action map. If so, the corresponding configuration will be used to create the action instance.

Parameters

$actionMap
array
$actionMap the action map
$actionID
string
$actionID the action ID that has its prefix stripped off
$requestActionID
string
$requestActionID the originally requested action ID
$config
array
$config the action configuration that should be applied on top of the configuration specified in the map

Returns

CAction
the action instance, null if the action does not exist.
public
# missingAction( string $actionID )

Handles the request whose action is not recognized. This method is invoked when the controller cannot find the requested action. The default implementation simply throws an exception.

Handles the request whose action is not recognized. This method is invoked when the controller cannot find the requested action. The default implementation simply throws an exception.

Parameters

$actionID
string
$actionID the missing action name

Throws

CHttpException
whenever this method is invoked
public CAction
# getAction( )

Returns

CAction
the action currently being executed, null if no active action.
public
# setAction( CAction $value )

Parameters

$value
CAction
$value the action currently being executed.
public string
# getId( )

Returns

string
ID of the controller
public string
# getUniqueId( )

Returns

string
the controller ID that is prefixed with the module ID (if any).
public string
# getRoute( )

Returns

string
the route (module ID, controller ID and action ID) of the current request.

Since

1.1.0
public CWebModule
# getModule( )

Returns

CWebModule
the module that this controller belongs to. It returns null if the controller does not belong to any module
public string
# getViewPath( )

Returns the directory containing view files for this controller. The default implementation returns 'protected/views/ControllerID'. Child classes may override this method to use customized view path. If the controller belongs to a module, the default view path is the CWebModule::getViewPath module view path appended with the controller ID.

Returns the directory containing view files for this controller. The default implementation returns 'protected/views/ControllerID'. Child classes may override this method to use customized view path. If the controller belongs to a module, the default view path is the CWebModule::getViewPath module view path appended with the controller ID.

Returns

string
the directory containing the view files for this controller. Defaults to 'protected/views/ControllerID'.
public string
# getViewFile( string $viewName )

Looks for the view file according to the given view name.

Looks for the view file according to the given view name.

When a theme is currently active, this method will call CTheme::getViewFile() to determine which view file should be returned.

Otherwise, this method will return the corresponding view file based on the following criteria:
  • absolute view within a module: the view name starts with a single slash '/'. In this case, the view will be searched for under the currently active module's view path. If there is no active module, the view will be searched for under the application's view path.
  • absolute view within the application: the view name starts with double slashes '//'. In this case, the view will be searched for under the application's view path. This syntax has been available since version 1.1.3.
  • aliased view: the view name contains dots and refers to a path alias. The view file is determined by calling YiiBase::getPathOfAlias(). Note that aliased views cannot be themed because they can refer to a view file located at arbitrary places.
  • relative view: otherwise. Relative views will be searched for under the currently active controller's view path.

After the view file is identified, this method may further call CApplication::findLocalizedFile() to find its localized version if internationalization is needed.

Parameters

$viewName
string
$viewName view name

Returns

string
the view file path, false if the view file does not exist

See

CController::resolveViewFile()
CApplication::findLocalizedFile()
public string
# getLayoutFile( mixed $layoutName )

Looks for the layout view script based on the layout name.

Looks for the layout view script based on the layout name.

The layout name can be specified in one of the following ways:

  • layout is false: returns false, meaning no layout.
  • layout is null: the currently active module's layout will be used. If there is no active module, the application's layout will be used.
  • a regular view name.

The resolution of the view file based on the layout view is similar to that in CController::getViewFile(). In particular, the following rules are followed:

Otherwise, this method will return the corresponding view file based on the following criteria:
  • When a theme is currently active, this method will call CTheme::getLayoutFile() to determine which view file should be returned.
  • absolute view within a module: the view name starts with a single slash '/'. In this case, the view will be searched for under the currently active module's view path. If there is no active module, the view will be searched for under the application's view path.
  • absolute view within the application: the view name starts with double slashes '//'. In this case, the view will be searched for under the application's view path. This syntax has been available since version 1.1.3.
  • aliased view: the view name contains dots and refers to a path alias. The view file is determined by calling YiiBase::getPathOfAlias(). Note that aliased views cannot be themed because they can refer to a view file located at arbitrary places.
  • relative view: otherwise. Relative views will be searched for under the currently active module's layout path. In case when there is no active module, the view will be searched for under the application's layout path.

After the view file is identified, this method may further call CApplication::findLocalizedFile() to find its localized version if internationalization is needed.

Parameters

$layoutName
mixed
$layoutName layout name

Returns

string
the view file for the layout. False if the view file cannot be found
public mixed
# resolveViewFile( string $viewName, string $viewPath, string $basePath, string $moduleViewPath = null )
Finds a view file based on its name. The view name can be in one of the following formats:
  • absolute view within a module: the view name starts with a single slash '/'. In this case, the view will be searched for under the currently active module's view path. If there is no active module, the view will be searched for under the application's view path.
  • absolute view within the application: the view name starts with double slashes '//'. In this case, the view will be searched for under the application's view path. This syntax has been available since version 1.1.3.
  • aliased view: the view name contains dots and refers to a path alias. The view file is determined by calling YiiBase::getPathOfAlias(). Note that aliased views cannot be themed because they can refer to a view file located at arbitrary places.
  • relative view: otherwise. Relative views will be searched for under the currently active controller's view path.
For absolute view and relative view, the corresponding view file is a PHP file whose name is the same as the view name. The file is located under a specified directory. This method will call CApplication::findLocalizedFile() to search for a localized file, if any.
Finds a view file based on its name. The view name can be in one of the following formats:
  • absolute view within a module: the view name starts with a single slash '/'. In this case, the view will be searched for under the currently active module's view path. If there is no active module, the view will be searched for under the application's view path.
  • absolute view within the application: the view name starts with double slashes '//'. In this case, the view will be searched for under the application's view path. This syntax has been available since version 1.1.3.
  • aliased view: the view name contains dots and refers to a path alias. The view file is determined by calling YiiBase::getPathOfAlias(). Note that aliased views cannot be themed because they can refer to a view file located at arbitrary places.
  • relative view: otherwise. Relative views will be searched for under the currently active controller's view path.
For absolute view and relative view, the corresponding view file is a PHP file whose name is the same as the view name. The file is located under a specified directory. This method will call CApplication::findLocalizedFile() to search for a localized file, if any.

Parameters

$viewName
string
$viewName the view name
$viewPath
string
$viewPath the directory that is used to search for a relative view name
$basePath
string
$basePath the directory that is used to search for an absolute view name under the application
$moduleViewPath
string
$moduleViewPath the directory that is used to search for an absolute view name under the current module. If this is not set, the application base view path will be used.

Returns

mixed
the view file path. False if the view file does not exist.
public CMap
# getClips( )

Returns the list of clips. A clip is a named piece of rendering result that can be inserted at different places.

Returns the list of clips. A clip is a named piece of rendering result that can be inserted at different places.

Returns

CMap
the list of clips

See

CClipWidget
public
# forward( string $route, boolean $exit = true )

Processes the request using another controller action. This is like CController::redirect(), but the user browser's URL remains unchanged. In most cases, you should call CController::redirect() instead of this method.

Processes the request using another controller action. This is like CController::redirect(), but the user browser's URL remains unchanged. In most cases, you should call CController::redirect() instead of this method.

Parameters

$route
string
$route the route of the new controller action. This can be an action ID, or a complete route with module ID (optional in the current module), controller ID and action ID. If the former, the action is assumed to be located within the current controller.
$exit
boolean
$exit whether to end the application after this call. Defaults to true.

Since

1.1.0
public string
# render( string $view, array $data = null, boolean $return = false )

Renders a view with a layout.

Renders a view with a layout.

This method first calls CController::renderPartial() to render the view (called content view). It then renders the layout view which may embed the content view at appropriate place. In the layout view, the content view rendering result can be accessed via variable <span class="php-var">$content</span>. At the end, it calls CController::processOutput() to insert scripts and dynamic contents if they are available.

By default, the layout view script is "protected/views/layouts/main.php". This may be customized by changing CController::$layout.

Parameters

$view
string
$view name of the view to be rendered. See CController::getViewFile() for details about how the view script is resolved.
$data
array
$data data to be extracted into PHP variables and made available to the view script
$return
boolean
$return whether the rendering result should be returned instead of being displayed to end users.

Returns

string
the rendering result. Null if the rendering result is not required.

See

CController::renderPartial()
CController::getLayoutFile()
protected boolean
# beforeRender( string $view )

This method is invoked at the beginning of CController::render(). You may override this method to do some preprocessing when rendering a view.

This method is invoked at the beginning of CController::render(). You may override this method to do some preprocessing when rendering a view.

Parameters

$view
string
$view the view to be rendered

Returns

boolean
whether the view should be rendered.

Since

1.1.5
protected
# afterRender( string $view, string & $output )

This method is invoked after the specified view is rendered by calling CController::render(). Note that this method is invoked BEFORE CController::processOutput(). You may override this method to do some postprocessing for the view rendering.

This method is invoked after the specified view is rendered by calling CController::render(). Note that this method is invoked BEFORE CController::processOutput(). You may override this method to do some postprocessing for the view rendering.

Parameters

$view
string
$view the view that has been rendered
$output
string
$output the rendering result of the view. Note that this parameter is passed as a reference. That means you can modify it within this method.

Since

1.1.5
public string
# renderText( string $text, boolean $return = false )

Renders a static text string. The string will be inserted in the current controller layout and returned back.

Renders a static text string. The string will be inserted in the current controller layout and returned back.

Parameters

$text
string
$text the static text string
$return
boolean
$return whether the rendering result should be returned instead of being displayed to end users.

Returns

string
the rendering result. Null if the rendering result is not required.

See

CController::getLayoutFile()
public string
# renderPartial( string $view, array $data = null, boolean $return = false, boolean $processOutput = false )

Renders a view.

Renders a view.

The named view refers to a PHP script (resolved via CController::getViewFile()) that is included by this method. If $data is an associative array, it will be extracted as PHP variables and made available to the script.

This method differs from CController::render() in that it does not apply a layout to the rendered result. It is thus mostly used in rendering a partial view, or an AJAX response.

Parameters

$view
string
$view name of the view to be rendered. See CController::getViewFile() for details about how the view script is resolved.
$data
array
$data data to be extracted into PHP variables and made available to the view script
$return
boolean
$return whether the rendering result should be returned instead of being displayed to end users
$processOutput
boolean
$processOutput whether the rendering result should be postprocessed using CController::processOutput().

Returns

string
the rendering result. Null if the rendering result is not required.

Throws

CException
if the view does not exist

See

CController::getViewFile()
CController::processOutput()
CController::render()
public mixed
# renderClip( string $name, array $params = array(), boolean $return = false )

Renders a named clip with the supplied parameters. This is similar to directly accessing the clips property. The main difference is that it can take an array of named parameters which will replace the corresponding placeholders in the clip.

Renders a named clip with the supplied parameters. This is similar to directly accessing the clips property. The main difference is that it can take an array of named parameters which will replace the corresponding placeholders in the clip.

Parameters

$name
string
$name the name of the clip
$params
array
$params an array of named parameters (name=>value) that should replace their corresponding placeholders in the clip
$return
boolean
$return whether to return the clip content or echo it.

Returns

mixed
either the clip content or null

Since

1.1.8
public
# renderDynamic( callable $callback )

Renders dynamic content returned by the specified callback. This method is used together with COutputCache. Dynamic contents will always show as their latest state even if the content surrounding them is being cached. This is especially useful when caching pages that are mostly static but contain some small dynamic regions, such as username or current time. We can use this method to render these dynamic regions to ensure they are always up-to-date.

Renders dynamic content returned by the specified callback. This method is used together with COutputCache. Dynamic contents will always show as their latest state even if the content surrounding them is being cached. This is especially useful when caching pages that are mostly static but contain some small dynamic regions, such as username or current time. We can use this method to render these dynamic regions to ensure they are always up-to-date.

The first parameter to this method should be a valid PHP callback, while the rest parameters will be passed to the callback.

Note, the callback and its parameter values will be serialized and saved in cache. Make sure they are serializable.

Parameters

$callback
callable
$callback a PHP callback which returns the needed dynamic content. When the callback is specified as a string, it will be first assumed to be a method of the current controller class. If the method does not exist, it is assumed to be a global PHP function. Note, the callback should return the dynamic content instead of echoing it.
public
# renderDynamicInternal( callable $callback, array $params )

This method is internally used.

This method is internally used.

Parameters

$callback
callable
$callback a PHP callback which returns the needed dynamic content.
$params
array
$params parameters passed to the PHP callback

See

CController::renderDynamic()
public string
# createUrl( string $route, array $params = array(), string $ampersand = '&' )

Creates a relative URL for the specified action defined in this controller.

Creates a relative URL for the specified action defined in this controller.

Parameters

$route
string
$route the URL route. This should be in the format of 'ControllerID/ActionID'. If the ControllerID is not present, the current controller ID will be prefixed to the route. If the route is empty, it is assumed to be the current action. If the controller belongs to a module, the CWebModule::getId module ID will be prefixed to the route. (If you do not want the module ID prefix, the route should start with a slash '/'.)
$params
array
$params additional GET parameters (name=>value). Both the name and value will be URL-encoded. If the name is '#', the corresponding value will be treated as an anchor and will be appended at the end of the URL.
$ampersand
string
$ampersand the token separating name-value pairs in the URL.

Returns

string
the constructed URL
public string
# createAbsoluteUrl( string $route, array $params = array(), string $schema = '', string $ampersand = '&' )

Creates an absolute URL for the specified action defined in this controller.

Creates an absolute URL for the specified action defined in this controller.

Parameters

$route
string
$route the URL route. This should be in the format of 'ControllerID/ActionID'. If the ControllerPath is not present, the current controller ID will be prefixed to the route. If the route is empty, it is assumed to be the current action.
$params
array
$params additional GET parameters (name=>value). Both the name and value will be URL-encoded.
$schema
string
$schema schema to use (e.g. http, https). If empty, the schema used for the current request will be used.
$ampersand
string
$ampersand the token separating name-value pairs in the URL.

Returns

string
the constructed URL
public string
# getPageTitle( )

Returns

string
the page title. Defaults to the controller name and the action name.
public
# setPageTitle( string $value )

Parameters

$value
string
$value the page title.
public
# redirect( mixed $url, boolean $terminate = true, integer $statusCode = 302 )

Redirects the browser to the specified URL or route (controller/action).

Redirects the browser to the specified URL or route (controller/action).

Parameters

$url
mixed
$url the URL to be redirected to. If the parameter is an array, the first element must be a route to a controller action and the rest are GET parameters in name-value pairs.
$terminate
boolean
$terminate whether to terminate the current application after calling this method. Defaults to true.
$statusCode
integer
$statusCode the HTTP status code. Defaults to 302. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for details about HTTP status code.
public
# refresh( boolean $terminate = true, string $anchor = '' )

Refreshes the current page. The effect of this method call is the same as user pressing the refresh button on the browser (without post data).

Refreshes the current page. The effect of this method call is the same as user pressing the refresh button on the browser (without post data).

Parameters

$terminate
boolean
$terminate whether to terminate the current application after calling this method
$anchor
string
$anchor the anchor that should be appended to the redirection URL. Defaults to empty. Make sure the anchor starts with '#' if you want to specify it.
public
# recordCachingAction( string $context, string $method, array $params )

Records a method call when an output cache is in effect. When the content is served from the output cache, the recorded method will be re-invoked.

Records a method call when an output cache is in effect. When the content is served from the output cache, the recorded method will be re-invoked.

Parameters

$context
string
$context a property name of the controller. It refers to an object whose method is being called. If empty it means the controller itself.
$method
string
$method the method name
$params
array
$params parameters passed to the method

See

COutputCache
public CStack
# getCachingStack( boolean $createIfNull = true )

Parameters

$createIfNull
boolean
$createIfNull whether to create a stack if it does not exist yet. Defaults to true.

Returns

CStack
stack of COutputCache objects
public boolean
# isCachingStackEmpty( )

Returns whether the caching stack is empty.

Returns whether the caching stack is empty.

Returns

boolean
whether the caching stack is empty. If not empty, it means currently there are some output cache in effect. Note, the return result of this method may change when it is called in different output regions, depending on the partition of output caches.
protected boolean
# beforeAction( CAction $action )

This method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action.

This method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action.

Parameters

$action
CAction
$action the action to be executed.

Returns

boolean
whether the action should be executed.
protected
# afterAction( CAction $action )

This method is invoked right after an action is executed. You may override this method to do some postprocessing for the action.

This method is invoked right after an action is executed. You may override this method to do some postprocessing for the action.

Parameters

$action
CAction
$action the action just executed.
public
# filterPostOnly( CFilterChain $filterChain )

The filter method for 'postOnly' filter. This filter throws an exception (CHttpException with code 400) if the applied action is receiving a non-POST request.

The filter method for 'postOnly' filter. This filter throws an exception (CHttpException with code 400) if the applied action is receiving a non-POST request.

Parameters

$filterChain
CFilterChain
$filterChain the filter chain that the filter is on.

Throws

CHttpException
if the current request is not a POST request
public
# filterAjaxOnly( CFilterChain $filterChain )

The filter method for 'ajaxOnly' filter. This filter throws an exception (CHttpException with code 400) if the applied action is receiving a non-AJAX request.

The filter method for 'ajaxOnly' filter. This filter throws an exception (CHttpException with code 400) if the applied action is receiving a non-AJAX request.

Parameters

$filterChain
CFilterChain
$filterChain the filter chain that the filter is on.

Throws

CHttpException
if the current request is not an AJAX request.
public
# filterAccessControl( CFilterChain $filterChain )

The filter method for 'accessControl' filter. This filter is a wrapper of CAccessControlFilter. To use this filter, you must override CController::accessRules() method.

The filter method for 'accessControl' filter. This filter is a wrapper of CAccessControlFilter. To use this filter, you must override CController::accessRules() method.

Parameters

$filterChain
CFilterChain
$filterChain the filter chain that the filter is on.
public mixed
# getPageState( string $name, mixed $defaultValue = null )

Returns a persistent page state value. A page state is a variable that is persistent across POST requests of the same page. In order to use persistent page states, the form(s) must be stateful which are generated using CHtml::statefulForm().

Returns a persistent page state value. A page state is a variable that is persistent across POST requests of the same page. In order to use persistent page states, the form(s) must be stateful which are generated using CHtml::statefulForm().

Parameters

$name
string
$name the state name
$defaultValue
mixed
$defaultValue the value to be returned if the named state is not found

Returns

mixed
the page state value

See

CController::setPageState()
CHtml::statefulForm()
public
# setPageState( string $name, mixed $value, mixed $defaultValue = null )

Saves a persistent page state value. A page state is a variable that is persistent across POST requests of the same page. In order to use persistent page states, the form(s) must be stateful which are generated using CHtml::statefulForm().

Saves a persistent page state value. A page state is a variable that is persistent across POST requests of the same page. In order to use persistent page states, the form(s) must be stateful which are generated using CHtml::statefulForm().

Parameters

$name
string
$name the state name
$value
mixed
$value the page state value
$defaultValue
mixed
$defaultValue the default page state value. If this is the same as the given value, the state will be removed from persistent storage.

See

CController::getPageState()
CHtml::statefulForm()
public
# clearPageStates( )

Removes all page states.

Removes all page states.

protected array
# loadPageStates( )

Loads page states from a hidden input.

Loads page states from a hidden input.

Returns

array
the loaded page states
protected
# savePageStates( array $states, string & $output )

Saves page states as a base64 string.

Saves page states as a base64 string.

Parameters

$states
array
$states the states to be saved.
$output
string
$output the output to be modified. Note, this is passed by reference.
Methods inherited from CBaseController
beginCache(), beginClip(), beginContent(), beginWidget(), createWidget(), endCache(), endClip(), endContent(), endWidget(), renderFile(), renderInternal(), widget()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Constants summary
string STATE_INPUT_NAME 'YII_PAGE_STATE'
#

Name of the hidden field storing persistent page states.

Name of the hidden field storing persistent page states.

Properties summary
public mixed $layout
#

the name of the layout to be applied to this controller's views. Defaults to null, meaning the CWebApplication::layout application layout is used. If it is false, no layout will be applied. The CWebModule::layout module layout will be used if the controller belongs to a module and this layout property is null.

the name of the layout to be applied to this controller's views. Defaults to null, meaning the CWebApplication::layout application layout is used. If it is false, no layout will be applied. The CWebModule::layout module layout will be used if the controller belongs to a module and this layout property is null.

public string $defaultAction 'index'
#

the name of the default action. Defaults to 'index'.

the name of the default action. Defaults to 'index'.

Magic properties summary
public array $actionParams
#

The request parameters to be used for action parameter binding.

The request parameters to be used for action parameter binding.

public CAction $action
#

The action currently being executed, null if no active action.

The action currently being executed, null if no active action.

public string $id
#

ID of the controller.

ID of the controller.

public string $uniqueId
#

The controller ID that is prefixed with the module ID (if any).

The controller ID that is prefixed with the module ID (if any).

public string $route
#

The route (module ID, controller ID and action ID) of the current request.

The route (module ID, controller ID and action ID) of the current request.

public CWebModule $module
#

The module that this controller belongs to. It returns null if the controller does not belong to any module.

The module that this controller belongs to. It returns null if the controller does not belong to any module.

public string $viewPath
#

The directory containing the view files for this controller. Defaults to 'protected/views/ControllerID'.

The directory containing the view files for this controller. Defaults to 'protected/views/ControllerID'.

public CMap $clips
#

The list of clips.

The list of clips.

public string $pageTitle
#

The page title. Defaults to the controller name and the action name.

The page title. Defaults to the controller name and the action name.

public CStack $cachingStack
#

Stack of COutputCache objects.

Stack of COutputCache objects.

API documentation generated by ApiGen 2.8.0