Package | system.web |
---|---|
Inheritance | class CController » CBaseController » CComponent |
Subclasses | CExtController |
Since | 1.0 |
Version | $Id$ |
Source Code | framework/web/CController.php |
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 a object-based filter whose class is 'system.web.widgets.COutputCache' and the 'duration' property is initialized as 300 (s).
$filterChain->run()
if the action should
be executed. Otherwise, the filtering process would stop at this filter.
Property | Type | Description | Defined By |
---|---|---|---|
action | CAction | the action currently being executed, null if no active action. | 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 |
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 |
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__construct() | CController | |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
accessRules() | Returns the access rules for this controller. | CController |
actions() | Returns a list of external action classes. | CController |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
beginCache() | Begins fragment caching. | CBaseController |
beginClip() | Begins recording a clip. | CBaseController |
beginContent() | Begins the rendering of content that is to be decorated by the specified view. | CBaseController |
beginWidget() | Creates a widget and executes it. | CBaseController |
behaviors() | Returns a list of behaviors that this controller should behave as. | CController |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
clearPageStates() | Removes all page states. | CController |
createAbsoluteUrl() | Creates an absolute URL for the specified action defined in this controller. | CController |
createAction() | Creates the action instance based on the action name. | CController |
createUrl() | Creates a relative URL for the specified action defined in this controller. | CController |
createWidget() | Creates a widget and initializes it. | CBaseController |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
endCache() | Ends fragment caching. | CBaseController |
endClip() | Ends recording a clip. | CBaseController |
endContent() | Ends the rendering of content. | CBaseController |
endWidget() | Ends the execution of the named widget. | CBaseController |
filterAccessControl() | The filter method for 'accessControl' filter. | CController |
filterAjaxOnly() | The filter method for 'ajaxOnly' filter. | CController |
filterPostOnly() | The filter method for 'postOnly' filter. | CController |
filters() | Returns the filter configurations. | CController |
getAction() | Returns the action currently being executed, null if no active action. | CController |
getCachingStack() | Returns stack of COutputCache objects | CController |
getClips() | Returns the list of clips. | CController |
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
getId() | Returns ID of the controller | CController |
getLayoutFile() | Looks for the view script file for a layout. | CController |
getModule() | Returns the module that this controller belongs to. It returns null if the controller does not belong to any module | CController |
getPageState() | Returns a persistent page state value. | CController |
getPageTitle() | Returns the page title. Defaults to the controller name and the action name. | CController |
getUniqueId() | Returns the controller ID that is prefixed with the module ID (if any). | CController |
getViewFile() | Looks for the view file according to the given view name. | CController |
getViewPath() | Returns the directory containing view files for this controller. | CController |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
init() | Initializes the controller. | CController |
isCachingStackEmpty() | CController | |
missingAction() | Handles the request whose action is not recognized. | CController |
paginate() | Generates pagination information. | CController |
processDynamicOutput() | Postprocesses the dynamic output. | CController |
processOutput() | Postprocesses the output generated by render(). | CController |
raiseEvent() | Raises an event. | CComponent |
recordCachingAction() | Records a method call when an output cache is in effect. | CController |
redirect() | Redirects the browser to the specified URL or route (controller/action). | CController |
refresh() | Refreshes the current page. | CController |
render() | Renders a view with a layout. | CController |
renderDynamic() | Renders dynamic content returned by the specified callback. | CController |
renderDynamicInternal() | This method is internally used. | CController |
renderFile() | Renders a view file. | CBaseController |
renderInternal() | Renders a view file. | CBaseController |
renderPartial() | Renders a view. | CController |
renderText() | Renders a static text string. | CController |
resolveViewFile() | Finds a view file based on its name. | CController |
run() | Runs the named action. | CController |
runAction() | Runs the action after passing through all filters. | CController |
runActionWithFilters() | Runs an action with the specified filters. | CController |
setAction() | Sets the action currently being executed. | CController |
setPageState() | Saves a persistent page state value. | CController |
setPageTitle() | Sets the page title. | CController |
widget() | Creates a widget and executes it. | CBaseController |
Method | Description | Defined By |
---|---|---|
afterAction() | This method is invoked right after an action is executed. | CController |
beforeAction() | This method is invoked right before an action is to be executed (after all possible filters.) | CController |
createActionFromMap() | Creates the action instance based on the action map. | CController |
loadPageStates() | Loads page states from a hidden input. | CController |
replaceDynamicOutput() | Replaces the dynamic content placeholders with actual content. | CController |
savePageStates() | Saves page states as a base64 string. | CController |
the action currently being executed, null if no active action.
stack of COutputCache objects
Returns the list of clips. A clip is a named piece of rendering result that can be inserted at different places.
the name of the default action. Defaults to 'index'.
ID of the controller
the name of the layout to be applied to this controller's views. Defaults to null, meaning the application layout is used. If it is false, no layout will be applied. Since version 1.0.3, the module layout will be used if the controller belongs to a module and this layout property is null.
the module that this controller belongs to. It returns null if the controller does not belong to any module
the page title. Defaults to the controller name and the action name.
the controller ID that is prefixed with the module ID (if any).
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 (since version 1.0.3), the default view path is the module view path appended with the controller ID.
public void __construct(string $id, CWebModule $module=NULL)
| ||
$id | string | id of this controller |
$module | CWebModule | the module that this controller belongs to. This parameter has been available since version 1.0.3. |
public function __construct($id,$module=null)
{
$this->_id=$id;
$this->_module=$module;
$this->attachBehaviors($this->behaviors());
}
public array accessRules()
| ||
{return} | array | list of access rules. See CAccessControlFilter for details about rule specification. |
public function accessRules()
{
return array();
}
Returns the access rules for this controller. Override this method if you use the accessControl filter.
public array actions()
| ||
{return} | array | list of external action classes |
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.
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', ), ), )
protected void afterAction(CAction $action)
| ||
$action | CAction | the action just executed. |
This method is invoked right after an action is executed. You may override this method to do some postprocessing for the action.
protected boolean beforeAction(CAction $action)
| ||
$action | CAction | the action to be executed. |
{return} | boolean | whether the action should be executed. |
protected function beforeAction($action)
{
return true;
}
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.
public array behaviors()
| ||
{return} | array | the behavior configurations (behavior name=>behavior configuration) |
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', )
public void clearPageStates()
|
public function clearPageStates()
{
$this->_pageStates=array();
}
Removes all page states.
public string createAbsoluteUrl(string $route, array $params=array (
), string $schema='', string $ampersand='&')
| ||
$route | string | 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 | additional GET parameters (name=>value). Both the name and value will be URL-encoded. |
$schema | string | schema to use (e.g. http, https). If empty, the schema used for the current request will be used. |
$ampersand | string | the token separating name-value pairs in the URL. |
{return} | string | the constructed URL |
public function createAbsoluteUrl($route,$params=array(),$schema='',$ampersand='&')
{
return Yii::app()->getRequest()->getHostInfo($schema).$this->createUrl($route,$params,$ampersand);
}
Creates an absolute URL for the specified action defined in this controller.
public CAction createAction(string $actionID)
| ||
$actionID | string | ID of the action. If empty, the default action will be used. |
{return} | CAction | the action instance, null if the action does not exist. |
public function createAction($actionID)
{
if($actionID==='')
$actionID=$this->defaultAction;
if(method_exists($this,'action'.$actionID) && strcasecmp($actionID,'s')) // we have actions method
return new CInlineAction($this,$actionID);
else
return $this->createActionFromMap($this->actions(),$actionID,$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 actions.
protected CAction createActionFromMap(array $actionMap, string $actionID, string $requestActionID, array $config=array (
))
| ||
$actionMap | array | the action map |
$actionID | string | the action ID that has its prefix stripped off |
$requestActionID | string | the originally requested action ID |
$config | array | the action configuration that should be applied on top of the configuration specified in the map |
{return} | CAction | the action instance, null if the action does not exist. |
protected function createActionFromMap($actionMap,$actionID,$requestActionID,$config=array())
{
if(($pos=strpos($actionID,'.'))===false && isset($actionMap[$actionID]))
{
$baseConfig=is_array($actionMap[$actionID]) ? $actionMap[$actionID] : array('class'=>$actionMap[$actionID]);
return Yii::createComponent(empty($config)?$baseConfig:array_merge($baseConfig,$config),$this,$requestActionID);
}
else if($pos===false)
return null;
// the action is defined in a provider
$prefix=substr($actionID,0,$pos+1);
if(!isset($actionMap[$prefix]))
return null;
$actionID=(string)substr($actionID,$pos+1);
$provider=$actionMap[$prefix];
if(is_string($provider))
$providerType=$provider;
else if(is_array($provider) && isset($provider['class']))
{
$providerType=$provider['class'];
if(isset($provider[$actionID]))
{
if(is_string($provider[$actionID]))
$config=array_merge(array('class'=>$provider[$actionID]),$config);
else
$config=array_merge($provider[$actionID],$config);
}
}
else
throw new CException(Yii::t('yii','Object configuration must be an array containing a "class" element.'));
$class=Yii::import($providerType,true);
$map=call_user_func(array($class,'actions'));
return $this->createActionFromMap($map,$actionID,$requestActionID,$config);
}
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.
public string createUrl(string $route, array $params=array (
), string $ampersand='&')
| ||
$route | string | 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. Since version 1.0.3, if the controller belongs to a module, the 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 | 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. This anchor feature has been available since version 1.0.1. |
$ampersand | string | the token separating name-value pairs in the URL. |
{return} | string | the constructed URL |
public function createUrl($route,$params=array(),$ampersand='&')
{
if($route==='')
$route=$this->getId().'/'.$this->getAction()->getId();
else if(strpos($route,'/')===false)
$route=$this->getId().'/'.$route;
if($route[0]!=='/' && ($module=$this->getModule())!==null)
$route=$module->getId().'/'.$route;
return Yii::app()->createUrl(trim($route,'/'),$params,$ampersand);
}
Creates a relative URL for the specified action defined in this controller.
public void filterAccessControl(CFilterChain $filterChain)
| ||
$filterChain | CFilterChain | the filter chain that the filter is on. |
public function filterAccessControl($filterChain)
{
$filter=new CAccessControlFilter;
$filter->setRules($this->accessRules());
$filter->filter($filterChain);
}
The filter method for 'accessControl' filter. This filter is a wrapper of CAccessControlFilter. To use this filter, you must override accessRules method.
public void filterAjaxOnly(CFilterChain $filterChain)
| ||
$filterChain | CFilterChain | the filter chain that the filter is on. |
public function filterAjaxOnly($filterChain)
{
if(Yii::app()->getRequest()->getIsAjaxRequest())
$filterChain->run();
else
throw new CHttpException(400,Yii::t('yii','Your request is not valid.'));
}
The filter method for 'ajaxOnly' filter. This filter reports an error if the applied action is receiving a non-AJAX request.
public void filterPostOnly(CFilterChain $filterChain)
| ||
$filterChain | CFilterChain | the filter chain that the filter is on. |
public function filterPostOnly($filterChain)
{
if(Yii::app()->getRequest()->getIsPostRequest())
$filterChain->run();
else
throw new CHttpException(400,Yii::t('yii','Your request is not valid.'));
}
The filter method for 'postOnly' filter. This filter reports an error if the applied action is receiving a non-POST request.
public array filters()
| ||
{return} | array | a list of 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.
public CAction getAction()
| ||
{return} | CAction | the action currently being executed, null if no active action. |
public function getAction()
{
return $this->_action;
}
public CStack getCachingStack(boolean $createIfNull=true)
| ||
$createIfNull | boolean | whether to create a stack if it does not exist yet. Defaults to true. |
{return} | CStack | stack of COutputCache objects |
public function getCachingStack($createIfNull=true)
{
if(!$this->_cachingStack)
$this->_cachingStack=new CStack;
return $this->_cachingStack;
}
public CMap getClips()
| ||
{return} | CMap | the list of clips |
public function getClips()
{
if($this->_clips!==null)
return $this->_clips;
else
return $this->_clips=new CMap;
}
Returns the list of clips. A clip is a named piece of rendering result that can be inserted at different places.
public string getId()
| ||
{return} | string | ID of the controller |
public string getLayoutFile(mixed $layoutName)
| ||
$layoutName | mixed | layout name |
{return} | string | the view file for the layout. False if the view file cannot be found |
public function getLayoutFile($layoutName)
{
if($layoutName===false)
return false;
if(($theme=Yii::app()->getTheme())!==null && ($layoutFile=$theme->getLayoutFile($this,$layoutName))!==false)
return $layoutFile;
if(empty($layoutName))
{
$module=$this->getModule();
while($module!==null)
{
if($module->layout===false)
return false;
if(!empty($module->layout))
break;
$module=$module->getParentModule();
}
if($module===null)
$module=Yii::app();
return $this->resolveViewFile($module->layout,$module->getLayoutPath(),$module->getViewPath());
}
else
{
if(($module=$this->getModule())===null)
$module=Yii::app();
return $this->resolveViewFile($layoutName,$module->getLayoutPath(),$module->getViewPath());
}
}
Looks for the view script file for a layout. This method will look for the view under the application's layoutPath. If the view name starts with '/', the view will be looked for under the application's viewPath. If the view name is null, the application's default layout will be used. If the view name is false, this method simply returns false. Since version 1.0.2, the view name can also refer to a path alias if it contains dot characters. Since version 1.0.3, if the controller belongs to a module, the view file will be searched under the module layout path, and if the view name is null, the module default layout will be used.
public CWebModule getModule()
| ||
{return} | CWebModule | the module that this controller belongs to. It returns null if the controller does not belong to any module |
public function getModule()
{
return $this->_module;
}
public mixed getPageState(string $name, mixed $defaultValue=NULL)
| ||
$name | string | the state name |
$defaultValue | mixed | the value to be returned if the named state is not found |
{return} | mixed | the page state value |
public function getPageState($name,$defaultValue=null)
{
if($this->_pageStates===null)
$this->_pageStates=$this->loadPageStates();
return isset($this->_pageStates[$name])?$this->_pageStates[$name]:$defaultValue;
}
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.
public string getPageTitle()
| ||
{return} | string | the page title. Defaults to the controller name and the action name. |
public function getPageTitle()
{
if($this->_pageTitle!==null)
return $this->_pageTitle;
else
{
$name=ucfirst(basename($this->getId()));
if($this->getAction()!==null && strcasecmp($this->getAction()->getId(),$this->defaultAction))
return $this->_pageTitle=Yii::app()->name.' - '.ucfirst($this->getAction()->getId()).' '.$name;
else
return $this->_pageTitle=Yii::app()->name.' - '.$name;
}
}
public string getUniqueId()
| ||
{return} | string | the controller ID that is prefixed with the module ID (if any). |
public function getUniqueId()
{
return $this->_module ? $this->_module->getId().'/'.$this->_id : $this->_id;
}
public string getViewFile(string $viewName)
| ||
$viewName | string | name of the view (without file extension) |
{return} | string | the view file path, false if the view file does not exist |
public function getViewFile($viewName)
{
if(($theme=Yii::app()->getTheme())!==null && ($viewFile=$theme->getViewFile($this,$viewName))!==false)
return $viewFile;
$module=$this->getModule();
$basePath=$module ? $module->getViewPath() : Yii::app()->getViewPath();
return $this->resolveViewFile($viewName,$this->getViewPath(),$basePath);
}
Looks for the view file according to the given view name. This method will look for the view under the controller's viewPath. If the view name starts with '/', the view will be looked for under the application's viewPath. The view script file is named as "ViewName.php". A localized view file may be returned if internationalization is needed. See CApplication::findLocalizedFile for more details. Since version 1.0.2, the view name can also refer to a path alias if it contains dot characters. Since version 1.0.3, if the controller belongs to a module, the view file will be searched under the module view path.
public string getViewPath()
| ||
{return} | string | the directory containing the view files for this controller. Defaults to 'protected/views/ControllerID'. |
public function getViewPath()
{
if(($module=$this->getModule())===null)
$module=Yii::app();
return $module->getViewPath().'/'.$this->getId();
}
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 (since version 1.0.3), the default view path is the module view path appended with the controller ID.
public void 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.
public whether isCachingStackEmpty()
| ||
{return} | 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. |
public function isCachingStackEmpty()
{
return $this->_cachingStack===null || !$this->_cachingStack->getCount();
}
protected array loadPageStates()
| ||
{return} | array | the loaded page states |
protected function loadPageStates()
{
if(!empty($_POST[self::STATE_INPUT_NAME]))
{
if(($data=base64_decode($_POST[self::STATE_INPUT_NAME]))!==false)
{
if(extension_loaded('zlib'))
$data=@gzuncompress($data);
if(($data=Yii::app()->getSecurityManager()->validateData($data))!==false)
return unserialize($data);
}
}
return array();
}
Loads page states from a hidden input.
public void missingAction(string $actionID)
| ||
$actionID | string | the missing action name |
public function missingAction($actionID)
{
throw new CHttpException(404,Yii::t('yii','The system is unable to find the requested action "{action}".',
array('{action}'=>$actionID==''?$this->defaultAction:$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.
public CPagination paginate(integer $itemCount, integer $pageSize=NULL, string $pageVar=NULL)
| ||
$itemCount | integer | the total item count |
$pageSize | integer | the page size. See CPagination for default value. |
$pageVar | string | the name of the GET variable storing the current page index. See CPagination for default value. |
{return} | CPagination | the pagination information |
public function paginate($itemCount,$pageSize=null,$pageVar=null)
{
$pages=new CPagination($itemCount);
if($pageSize!==null)
$pages->pageSize=$pageSize;
if($pageVar!==null)
$pages->pageVar=$pageVar;
return $pages;
}
Generates pagination information.
This method can be used to generate pagination information given item count
and page size. The pagination information can then be passed to pagers
for corresponding rendering.
Note: this method has been deprecated since version 1.0.1.
You should directly use "new CPagination" to create a pagination object.
public string processDynamicOutput(string $output)
| ||
$output | string | output to be processed |
{return} | string | the processed output |
public function processDynamicOutput($output)
{
if($this->_dynamicOutput)
{
$output=preg_replace_callback('/<###dynamic-(\d+)###>/',array($this,'replaceDynamicOutput'),$output);
$this->_dynamicOutput=null;
}
return $output;
}
Postprocesses the dynamic output. This method is internally used. Do not call this method directly.
public string processOutput(string $output)
| ||
$output | string | the output generated by the current action |
{return} | string | the output that has been processed. |
public function processOutput($output)
{
Yii::app()->getClientScript()->render($output);
// if using page caching, we should delay dynamic output replacement
if($this->_dynamicOutput!==null && $this->isCachingStackEmpty())
$output=$this->processDynamicOutput($output);
if($this->_pageStates===null)
$this->_pageStates=$this->loadPageStates();
if(!empty($this->_pageStates))
$this->savePageStates($this->_pageStates,$output);
return $output;
}
Postprocesses the output generated by render(). This method is invoked at the end of render() and 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.
public void recordCachingAction(string $context, string $method, array $params)
| ||
$context | string | 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 | the method name |
$params | array | parameters passed to the method |
public function recordCachingAction($context,$method,$params)
{
if($this->_cachingStack) // record only when there is an active output cache
{
foreach($this->_cachingStack as $cache)
$cache->recordAction($context,$method,$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.
public void redirect(mixed $url, boolean $terminate=true, integer $statusCode=302)
| ||
$url | mixed | 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 | whether to terminate the current application after calling this method |
$statusCode | integer | the HTTP status code. Defaults to 302. See https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for details about HTTP status code. This parameter has been available since version 1.0.4. |
public function redirect($url,$terminate=true,$statusCode=302)
{
if(is_array($url))
{
$route=isset($url[0]) ? $url[0] : '';
$url=$this->createUrl($route,array_splice($url,1));
}
Yii::app()->getRequest()->redirect($url,$terminate,$statusCode);
}
Redirects the browser to the specified URL or route (controller/action).
public void refresh(boolean $terminate=true, string $anchor='')
| ||
$terminate | boolean | whether to terminate the current application after calling this method |
$anchor | string | 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. The parameter has been available since version 1.0.7. |
public function refresh($terminate=true,$anchor='')
{
$this->redirect(Yii::app()->getRequest()->getUrl().$anchor,$terminate);
}
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).
public string render(string $view, array $data=NULL, boolean $return=false)
| ||
$view | string | name of the view to be rendered. See getViewFile for details about how the view script is resolved. |
$data | array | data to be extracted into PHP variables and made available to the view script |
$return | boolean | whether the rendering result should be returned instead of being displayed to end users. |
{return} | string | the rendering result. Null if the rendering result is not required. |
public function render($view,$data=null,$return=false)
{
$output=$this->renderPartial($view,$data,true);
if(($layoutFile=$this->getLayoutFile($this->layout))!==false)
$output=$this->renderFile($layoutFile,array('content'=>$output),true);
$output=$this->processOutput($output);
if($return)
return $output;
else
echo $output;
}
Renders a view with a layout.
This method first calls 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
$content
. At the end, it calls 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 layout.
public void renderDynamic(callback $callback)
| ||
$callback | 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 function renderDynamic($callback)
{
$n=count($this->_dynamicOutput);
echo "<###dynamic-$n###>";
$params=func_get_args();
array_shift($params);
$this->renderDynamicInternal($callback,$params);
}
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.
public void renderDynamicInternal(callback $callback, array $params)
| ||
$callback | callback | a PHP callback which returns the needed dynamic content. |
$params | array | parameters passed to the PHP callback |
public function renderDynamicInternal($callback,$params)
{
$this->recordCachingAction('','renderDynamicInternal',array($callback,$params));
if(is_string($callback) && method_exists($this,$callback))
$callback=array($this,$callback);
$this->_dynamicOutput[]=call_user_func_array($callback,$params);
}
This method is internally used.
public string renderPartial(string $view, array $data=NULL, boolean $return=false, boolean $processOutput=false)
| ||
$view | string | name of the view to be rendered. See getViewFile for details about how the view script is resolved. |
$data | array | data to be extracted into PHP variables and made available to the view script |
$return | boolean | whether the rendering result should be returned instead of being displayed to end users |
$processOutput | boolean | whether the rendering result should be postprocessed using processOutput. This parameter should be set true if renderPartial is the only method used to generate the output when handling a user request. |
{return} | string | the rendering result. Null if the rendering result is not required. |
public function renderPartial($view,$data=null,$return=false,$processOutput=false)
{
if(($viewFile=$this->getViewFile($view))!==false)
{
$output=$this->renderFile($viewFile,$data,true);
if($processOutput)
$output=$this->processOutput($output);
if($return)
return $output;
else
echo $output;
}
else
throw new CException(Yii::t('yii','{controller} cannot find the requested view "{view}".',
array('{controller}'=>get_class($this), '{view}'=>$view)));
}
Renders a view.
The named view refers to a PHP script (resolved via 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 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.
public string renderText(string $text, boolean $return=false)
| ||
$text | string | the static text string |
$return | boolean | whether the rendering result should be returned instead of being displayed to end users. |
{return} | string | the rendering result. Null if the rendering result is not required. |
public function renderText($text,$return=false)
{
if(($layoutFile=$this->getLayoutFile($this->layout))!==false)
$text=$this->renderFile($layoutFile,array('content'=>$text),true);
$text=$this->processOutput($text);
if($return)
return $text;
else
echo $text;
}
Renders a static text string. The string will be inserted in the current controller layout and returned back.
protected string replaceDynamicOutput(array $matches)
| ||
$matches | array | matches |
{return} | string | the replacement |
protected function replaceDynamicOutput($matches)
{
return isset($this->_dynamicOutput[$matches[1]]) ? $this->_dynamicOutput[$matches[1]] : $matches[0];
}
Replaces the dynamic content placeholders with actual content. This is a callback function used internally.
public mixed resolveViewFile(string $viewName, string $viewPath, string $basePath)
| ||
$viewName | string | the view name |
$viewPath | string | the directory that is used to search for a relative view name |
$basePath | string | the directory that is used to search for an absolute view name |
{return} | mixed | the view file path. False if the view file does not exist. |
public function resolveViewFile($viewName,$viewPath,$basePath)
{
if(empty($viewName))
return false;
if(($renderer=Yii::app()->getViewRenderer())!==null)
$extension=$renderer->fileExtension;
else
$extension='.php';
if($viewName[0]==='/')
$viewFile=$basePath.$viewName.$extension;
else if(strpos($viewName,'.'))
$viewFile=Yii::getPathOfAlias($viewName).$extension;
else
$viewFile=$viewPath.DIRECTORY_SEPARATOR.$viewName.$extension;
return is_file($viewFile) ? Yii::app()->findLocalizedFile($viewFile) : false;
}
Finds a view file based on its name. The view name can be in one of the following formats:
public void run(string $actionID)
| ||
$actionID | string | action ID |
public function run($actionID)
{
if(($action=$this->createAction($actionID))!==null)
{
if(($parent=$this->getModule())===null)
$parent=Yii::app();
if($parent->beforeControllerAction($this,$action))
{
$this->runActionWithFilters($action,$this->filters());
$parent->afterControllerAction($this,$action);
}
}
else
$this->missingAction($actionID);
}
Runs the named action. Filters specified via filters() will be applied.
public void runAction(CAction $action)
| ||
$action | CAction | action to run |
public function runAction($action)
{
$priorAction=$this->_action;
$this->_action=$action;
if($this->beforeAction($action))
{
$action->run();
$this->afterAction($action);
}
$this->_action=$priorAction;
}
Runs the action after passing through all filters. This method is invoked by runActionWithFilters after all possible filters have been executed and the action starts to run.
public void runActionWithFilters(CAction $action, array $filters)
| ||
$action | CAction | the action to be executed. |
$filters | array | list of filters to be applied to the action. |
public function runActionWithFilters($action,$filters)
{
if(empty($filters))
$this->runAction($action);
else
{
$priorAction=$this->_action;
$this->_action=$action;
CFilterChain::create($this,$action,$filters)->run();
$this->_action=$priorAction;
}
}
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.
protected void savePageStates(array $states, string &$output)
| ||
$states | array | the states to be saved. |
$output | string | the output to be modified. Note, this is passed by reference. |
protected function savePageStates($states,&$output)
{
$data=Yii::app()->getSecurityManager()->hashData(serialize($states));
if(extension_loaded('zlib'))
$data=gzcompress($data);
$value=base64_encode($data);
$output=str_replace(CHtml::pageStateField(''),CHtml::pageStateField($value),$output);
}
Saves page states as a base64 string.
public void setAction(CAction $value)
| ||
$value | CAction | the action currently being executed. |
public function setAction($value)
{
$this->_action=$value;
}
public void setPageState(string $name, mixed $value, mixed $defaultValue=NULL)
| ||
$name | string | the state name |
$value | mixed | the page state value |
$defaultValue | mixed | the default page state value. If this is the same as the given value, the state will be removed from persistent storage. |
public function setPageState($name,$value,$defaultValue=null)
{
if($this->_pageStates===null)
$this->_pageStates=$this->loadPageStates();
if($value===$defaultValue)
unset($this->_pageStates[$name]);
else
$this->_pageStates[$name]=$value;
$params=func_get_args();
$this->recordCachingAction('','setPageState',$params);
}
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.
public void setPageTitle(string $value)
| ||
$value | string | the page title. |
public function setPageTitle($value)
{
$this->_pageTitle=$value;
}
Signup or Login in order to comment.