BaseController
Implements ControllerInterface, \Joomla\Event\DispatcherAwareInterfaceBase class for a Joomla Controller
Controller (Controllers are where you put all the actual code.) Provides basic functionality, such as rendering views (aka displaying templates).
since |
2.5.5 |
---|---|
package |
Joomla CMS |
Methods
__construct
Constructor.
__construct(array config = array(), \Joomla\CMS\MVC\Factory\MVCFactoryInterface factory = null, \Joomla\CMS\Application\CMSApplication app = null, \Joomla\Input\Input input = null) : mixed
since |
3.0 |
---|
Arguments
- config
array
An optional associative array of configuration settings. Recognized key values include 'name', 'default_task', 'model_path', and 'view_path' (this list is not meant to be comprehensive).- factory
\Joomla\CMS\MVC\Factory\MVCFactoryInterface
The factory.- app
\Joomla\CMS\Application\CMSApplication
The Application for the dispatcher- input
\Joomla\Input\Input
Input
Response
mixed
addModelPath
Adds to the stack of model paths in LIFO order.
addModelPath(mixed path, string prefix = '') : void
since |
3.0 |
---|---|
deprecated |
5.0 See \Joomla\CMS\MVC\Model\LegacyModelLoaderTrait::getInstance |
Arguments
- path
mixed
The directory (string), or list of directories (array) to add.- prefix
string
A prefix for models
addPath
Adds to the search path for templates and resources.
addPath(string type, mixed path) : static
since |
3.0 |
---|
Arguments
- type
string
The path type (e.g. 'model', 'view').- path
mixed
The directory string or stream array to search.
Response
static
A \JControllerLegacy object to support chaining.
addViewPath
Add one or more view paths to the controller's stack, in LIFO order.
addViewPath(mixed path) : static
since |
3.0 |
---|
Arguments
- path
mixed
The directory (string) or list of directories (array) to add.
Response
static
This object to support chaining.
checkEditId
Method to check whether an ID is in the edit list.
checkEditId(string context, int id) : bool
since |
3.0 |
---|
Arguments
- context
string
The context for the session storage.- id
int
The ID of the record to add to the edit list.
Response
bool
True if the ID is in the edit list.
checkToken
Checks for a form token in the request.
checkToken(string method = 'post', bool redirect = true) : bool
Use in conjunction with HTMLHelper::_('form.token') or Session::getFormToken.
since |
3.7.0 |
---|---|
see | Session::checkToken() |
Arguments
- method
string
The request method in which to look for the token key.- redirect
bool
Whether to implicitly redirect user to the referrer page on failure or simply return false.
Response
bool
True if found and valid, otherwise return false or redirect to referrer page.
createFileName
Create the filename for a resource.
createFileName(string type, array parts = array()) : string
since |
3.0 |
---|
Arguments
- type
string
The resource type to create the filename for.- parts
array
An associative array of filename information. Optional.
Response
string
The filename.
createModel
Method to load and return a model object.
createModel(string name, string prefix = '', array config = array()) : \Joomla\CMS\MVC\Model\BaseDatabaseModel|bool
since |
3.0 |
---|
Arguments
- name
string
The name of the model.- prefix
string
Optional model prefix.- config
array
Configuration array for the model. Optional.
Response
\Joomla\CMS\MVC\Model\BaseDatabaseModel|bool
Model object on success; otherwise false on failure.
createView
Method to load and return a view object. This method first looks in the current template directory for a match and, failing that, uses a default set path to load the view class file.
createView(string name, string prefix = '', string type = '', array config = array()) : \Joomla\CMS\MVC\View\ViewInterface|null
Note the "name, prefix, type" order of parameters, which differs from the "name, type, prefix" order used in related public methods.
since |
3.0 |
---|---|
throws |
|
Arguments
- name
string
The name of the view.- prefix
string
Optional prefix for the view class name.- type
string
The type of view.- config
array
Configuration array for the view. Optional.
Response
\Joomla\CMS\MVC\View\ViewInterface|null
View object on success; null or error result on failure.
display
Typical view method for MVC based architecture
display(bool cachable = false, array urlparams = array()) : static
This function is provide as a default implementation, in most cases you will need to override it in your own controllers.
since |
3.0 |
---|---|
throws |
|
Arguments
- cachable
bool
If true, the view output will be cached- urlparams
array
An array of safe url parameters and their variable types, for valid values see {@link InputFilter::clean()}.
Response
static
A \JControllerLegacy object to support chaining.
execute
Execute a task by triggering a method in the derived class.
execute(string task) : mixed
since |
3.0 |
---|---|
throws |
|
Arguments
- task
string
The task to perform. If no matching task is found, the '__default' task is executed, if defined.
Response
mixed
The value returned by the called method.
getInstance
Method to get a singleton controller instance.
getInstance(string prefix, array config = array()) : static
since |
3.0 |
---|---|
deprecated |
5.0 Get the controller through the MVCFactory instead |
throws |
|
Arguments
- prefix
string
The prefix for the controller.- config
array
An array of optional constructor options.
Response
static
getModel
Method to get a model object, loading it if required.
getModel(string name = '', string prefix = '', array config = array()) : \Joomla\CMS\MVC\Model\BaseDatabaseModel|bool
since |
3.0 |
---|
Arguments
- name
string
The model name. Optional.- prefix
string
The class prefix. Optional.- config
array
Configuration array for model. Optional.
Response
\Joomla\CMS\MVC\Model\BaseDatabaseModel|bool
Model object on success; otherwise false on failure.
getName
Method to get the controller name
getName() : string
The dispatcher name is set by default parsed using the classname, or it can be set by passing a $config['name'] in the class constructor
since |
3.0 |
---|---|
throws |
|
Response
string
The name of the dispatcher
getTask
Get the last task that is being performed or was most recently performed.
getTask() : string
since |
3.0 |
---|
Response
string
The task that is being performed or was most recently performed.
getTasks
Gets the available tasks in the controller.
getTasks() : array
since |
3.0 |
---|
Response
array
Array[i] of task names.
getView
Method to get a reference to the current view and load it if necessary.
getView(string name = '', string type = '', string prefix = '', array config = array()) : \Joomla\CMS\MVC\View\ViewInterface
since |
3.0 |
---|---|
throws |
|
Arguments
- name
string
The view name. Optional, defaults to the controller name.- type
string
The view type. Optional.- prefix
string
The class prefix. Optional.- config
array
Configuration array for view. Optional.
Response
\Joomla\CMS\MVC\View\ViewInterface
Reference to the view or an error.
holdEditId
Method to add a record ID to the edit list.
holdEditId(string context, int id) : void
since |
3.0 |
---|
Arguments
- context
string
The context for the session storage.- id
int
The ID of the record to add to the edit list.
redirect
Redirects the browser or returns false if no redirect is set.
redirect() : bool
since |
3.0 |
---|
Response
bool
False if no redirect exists.
registerDefaultTask
Register the default task to perform if a mapping is not found.
registerDefaultTask(string method) : static
since |
3.0 |
---|
Arguments
- method
string
The name of the method in the derived class to perform if a named task is not found.
Response
static
A \JControllerLegacy object to support chaining.
registerTask
Register (map) a task to a method in the class.
registerTask(string task, string method) : static
since |
3.0 |
---|
Arguments
- task
string
The task.- method
string
The name of the method in the derived class to perform for this task.
Response
static
A \JControllerLegacy object to support chaining.
releaseEditId
Method to check whether an ID is in the edit list.
releaseEditId(string context, int id) : void
since |
3.0 |
---|
Arguments
- context
string
The context for the session storage.- id
int
The ID of the record to add to the edit list.
setMessage
Sets the internal message that is passed with a redirect
setMessage(string text, string type = 'message') : string
since |
3.0 |
---|
Arguments
- text
string
Message to display on redirect.- type
string
Message type. Optional, defaults to 'message'.
Response
string
Previous message
setPath
Sets an entire array of search paths for resources.
setPath(string type, string path) : void
since |
3.0 |
---|
Arguments
- type
string
The type of path to set, typically 'view' or 'model'.- path
string
The new set of search paths. If null or false, resets to the current directory only.
setRedirect
Set a URL for browser redirection.
setRedirect(string url, string msg = null, string type = null) : static
since |
3.0 |
---|
Arguments
- url
string
URL to redirect to.- msg
string
Message to display on redirect. Optional, defaults to value set internally by controller, if any.- type
string
Message type. Optional, defaults to 'message' or the type set by a previous call to setMessage.
Response
static
This object to support chaining.
unregisterTask
Unregister (unmap) a task in the class.
unregisterTask(string task) : static
since |
3.0 |
---|
Arguments
- task
string
The task.
Response
static
This object to support chaining.
Properties
input
Hold a JInput object for easier access to the input variables.
since |
3.0 |
---|
Type(s)
\Joomla\Input\Input