BaseController
- Type
- Abstract Class
- Namespace
- Craft
- Inherits
- Craft\BaseController » CController (opens new window) » CBaseController (opens new window) » CComponent (opens new window)
- Extended by
- Craft\AppController, Craft\AssetSourcesController, Craft\AssetTransformsController, Craft\AssetsController, Craft\BaseElementsController, Craft\BaseEntriesController, Craft\CategoriesController, Craft\ChartsController, Craft\DashboardController, Craft\ElementIndexController, Craft\ElementIndexSettingsController, Craft\ElementsController, Craft\EmailMessagesController, Craft\EntriesController, Craft\EntryRevisionsController, Craft\FieldsController, Craft\GlobalsController, Craft\InstallController, Craft\LocalizationController, Craft\PluginsController, Craft\RebrandController, Craft\RoutesController, Craft\SectionsController, Craft\StructuresController, Craft\SystemSettingsController, Craft\TagsController, Craft\TasksController, Craft\TemplatesController, Craft\ToolsController, Craft\UpdateController, Craft\UserSettingsController, Craft\UsersController, Craft\UtilsController
- Since
- 1.0
BaseController is a base class that all controllers in Craft extend.
It extend's Yii's {@link \CController} overwriting specific methods as required.
See also http://craftcms.com
View source (opens new window)
# Public Properties
Property | Description |
---|---|
$defaultAction (opens new window) | string (opens new window) – The name of the default action. |
$layout (opens new window) | mixed – The name of the layout to be applied to this controller's views. |
# Protected Properties
Property | Description |
---|---|
$allowAnonymous | boolean (opens new window) |
# $allowAnonymous
Signature
protected boolean $allowAnonymous = false
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__construct() (opens new window) | |
__get() (opens new window) | Returns a property value, an event handler list or a behavior based on its name. |
__isset() (opens new window) | Checks if a property value is null. |
__set() (opens new window) | Sets value of a component property. |
__unset() (opens new window) | Sets a component property to be null. |
accessRules() (opens new window) | Returns the access rules for this controller. |
actions() (opens new window) | Returns a list of external action classes. |
asa() (opens new window) | Returns the named behavior object. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
attachEventHandler() (opens new window) | Attaches an event handler to an event. |
beforeAction() | Checks if a controller has overridden allowAnonymous either as an array with actions to allow anonymous access to or as a bool that applies to all actions. |
beginCache() (opens new window) | Begins fragment caching. |
beginClip() (opens new window) | Begins recording a clip. |
beginContent() (opens new window) | Begins the rendering of content that is to be decorated by the specified view. |
beginWidget() (opens new window) | Creates a widget and executes it. |
behaviors() (opens new window) | Returns a list of behaviors that this controller should behave as. |
canGetProperty() (opens new window) | Determines whether a property can be read. |
canSetProperty() (opens new window) | Determines whether a property can be set. |
clearPageStates() (opens new window) | Removes all page states. |
createAbsoluteUrl() (opens new window) | Creates an absolute URL for the specified action defined in this controller. |
createAction() (opens new window) | Creates the action instance based on the action name. |
createUrl() (opens new window) | Creates a relative URL for the specified action defined in this controller. |
createWidget() (opens new window) | Creates a widget and initializes it. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
detachEventHandler() (opens new window) | Detaches an existing event handler. |
disableBehavior() (opens new window) | Disables an attached behavior. |
disableBehaviors() (opens new window) | Disables all behaviors attached to this component. |
enableBehavior() (opens new window) | Enables an attached behavior. |
enableBehaviors() (opens new window) | Enables all behaviors attached to this component. |
endCache() (opens new window) | Ends fragment caching. |
endClip() (opens new window) | Ends recording a clip. |
endContent() (opens new window) | Ends the rendering of content. |
endWidget() (opens new window) | Ends the execution of the named widget. |
evaluateExpression() (opens new window) | Evaluates a PHP expression or callback under the context of this component. |
filterAccessControl() (opens new window) | The filter method for 'accessControl' filter. |
filterAjaxOnly() (opens new window) | The filter method for 'ajaxOnly' filter. |
filterPostOnly() (opens new window) | The filter method for 'postOnly' filter. |
filters() (opens new window) | Returns the filter configurations. |
forward() (opens new window) | Processes the request using another controller action. |
getAction() (opens new window) | |
getActionParams() | Returns the request parameters that will be used for action parameter binding. |
getCachingStack() (opens new window) | |
getClips() (opens new window) | Returns the list of clips. |
getEventHandlers() (opens new window) | Returns the list of attached event handlers for an event. |
getId() (opens new window) | |
getLayoutFile() (opens new window) | Looks for the layout view script based on the layout name. |
getModule() (opens new window) | |
getPageState() (opens new window) | Returns a persistent page state value. |
getPageTitle() (opens new window) | |
getRoute() (opens new window) | |
getUniqueId() (opens new window) | |
getViewFile() (opens new window) | Returns the view script file according to the specified view name. |
getViewPath() (opens new window) | Returns the directory containing view files for this controller. |
hasEvent() (opens new window) | Determines whether an event is defined. |
hasEventHandler() (opens new window) | Checks whether the named event has attached handlers. |
hasProperty() (opens new window) | Determines whether a property is defined. |
init() (opens new window) | Initializes the controller. |
invalidActionParams() (opens new window) | This method is invoked when the request parameters do not satisfy the requirement of the specified action. |
isCachingStackEmpty() (opens new window) | Returns whether the caching stack is empty. |
missingAction() (opens new window) | Handles the request whose action is not recognized. |
processDynamicOutput() (opens new window) | Postprocesses the dynamic output. |
processOutput() (opens new window) | Postprocesses the output generated by {@link render()}. |
raiseEvent() (opens new window) | Raises an event. |
recordCachingAction() (opens new window) | Records a method call when an output cache is in effect. |
redirect() | Redirects the browser to a given URL. |
redirectToPostedUrl() | Redirects to the URI specified in the POST. |
refresh() (opens new window) | Refreshes the current page. |
render() (opens new window) | Renders a view with a layout. |
renderClip() (opens new window) | Renders a named clip with the supplied parameters. |
renderDynamic() (opens new window) | Renders dynamic content returned by the specified callback. |
renderDynamicInternal() (opens new window) | This method is internally used. |
renderFile() (opens new window) | Renders a view file. |
renderInternal() (opens new window) | Renders a view file. |
renderPartial() (opens new window) | Renders a view. |
renderTemplate() | Renders a template, and either outputs or returns it. |
renderText() (opens new window) | Renders a static text string. |
requireAdmin() | Throws a 403 error if the current user is not an admin. |
requireAjaxRequest() | Throws a 400 error if this isn’t an Ajax request. |
requireElevatedSession() | Requires that the user has an elevated session. |
requireLogin() | Redirects the user to the login template if they're not logged in. |
requirePostRequest() | Throws a 400 error if this isn’t a POST request |
requireToken() | Throws a 400 error if the current request doesn’t have a valid token. |
resolveViewFile() (opens new window) | Finds a view file based on its name. |
returnErrorJson() | Responds to the request with a JSON error message. |
returnJson() | Responds to the request with JSON. |
run() (opens new window) | Runs the named action. |
runAction() (opens new window) | Runs the action after passing through all filters. |
runActionWithFilters() (opens new window) | Runs an action with the specified filters. |
setAction() (opens new window) | |
setPageState() (opens new window) | Saves a persistent page state value. |
setPageTitle() (opens new window) | |
widget() (opens new window) | Creates a widget and executes it. |
# beforeAction()
Checks if a controller has overridden allowAnonymous either as an array with actions to allow anonymous access to or as a bool that applies to all actions.
View source (opens new window)
Arguments
$action
(CAction (opens new window))
Returns
Signature
public boolean beforeAction ( $action )
# getActionParams()
Returns the request parameters that will be used for action parameter binding. By default, this method will return $_GET merged with {@link UrlManager::getRouteParams}.
View source (opens new window)
Returns
array (opens new window) – The request parameters to be used for action parameter binding.
Signature
public array getActionParams ( )
# redirect()
Redirects the browser to a given URL.
View source (opens new window)
Arguments
$url
(string (opens new window)) – The URL to redirect the browser to.$terminate
(boolean (opens new window)) – Whether the request should be terminated.$statusCode
(integer (opens new window)) – The status code to accompany the redirect. (Default is 302.)
Returns
Signature
public null redirect ( $url, $terminate = true, $statusCode = 302 )
# redirectToPostedUrl()
Redirects to the URI specified in the POST.
View source (opens new window)
Arguments
$object
(mixed
) – Object containing properties that should be parsed for in the URL.$default
(string (opens new window)) – The default URL to redirect them to, if no 'redirect' parameter exists. If this is left null, then the current request’s path will be used.
Returns
Signature
public null redirectToPostedUrl ( $object = null, $default = null )
# renderTemplate()
Renders a template, and either outputs or returns it.
View source (opens new window)
Arguments
$template
(mixed
) – The name of the template to load in a format supported by {@link TemplatesService::findTemplate()}, or a {@link StringTemplate} object.$variables
(array (opens new window)) – The variables that should be available to the template.$return
(boolean (opens new window)) – Whether to return the results, rather than output them. (Default isfalse
.)$processOutput
(boolean (opens new window)) – Whether the output should be processed by {@link processOutput()}.
Returns
mixed
– The rendered template if $return is set to true
.
Throws
Signature
public mixed renderTemplate ( $template, $variables = [], $return = false, $processOutput = false )
# requireAdmin()
Throws a 403 error if the current user is not an admin.
View source (opens new window)
Returns
Throws
Signature
public null requireAdmin ( )
# requireAjaxRequest()
Signature
public null requireAjaxRequest ( )
# requireElevatedSession()
Requires that the user has an elevated session.
Signature
public void requireElevatedSession ( )
# requireLogin()
Redirects the user to the login template if they're not logged in.
View source (opens new window)
Returns
Signature
public null requireLogin ( )
# requirePostRequest()
Signature
public null requirePostRequest ( )
# requireToken()
Throws a 400 error if the current request doesn’t have a valid token.
View source (opens new window)
Returns
Throws
Signature
public null requireToken ( )
# returnErrorJson()
Responds to the request with a JSON error message.
View source (opens new window)
Arguments
$error
(string (opens new window)) – The error message.
Returns
Signature
public null returnErrorJson ( $error )
# returnJson()
Responds to the request with JSON.
View source (opens new window)
Arguments
$var
(array (opens new window)) – The array that should be JSON-encoded and returned to the browser.$options
(array (opens new window)) – An array of options.
The $options array can contain the following values:
'expires'
- Sets the Expires header value (in seconds). Defaults tofalse
, which prevents the response from getting cached. If set tonull
, no Expires header will be set.
Returns
Signature
public null returnJson ( $var = [], $options = [] )
# Protected Methods
Method | Description |
---|---|
afterAction() (opens new window) | This method is invoked right after an action is executed. |
afterRender() (opens new window) | This method is invoked after the specified view is rendered by calling {@link render()}. |
beforeRender() (opens new window) | This method is invoked at the beginning of {@link render()}. |
createActionFromMap() (opens new window) | Creates the action instance based on the action map. |
loadPageStates() (opens new window) | Loads page states from a hidden input. |
replaceDynamicOutput() (opens new window) | Replaces the dynamic content placeholders with actual content. |
savePageStates() (opens new window) | Saves page states as a base64 string. |
# Constants
Constant | Description |
---|---|
STATE_INPUT_NAME | Name of the hidden field storing persistent page states. |