FormController
Extends BaseController Implements FormFactoryAwareInterfaceController tailored to suit most form-based admin operations.
since |
1.6 |
---|---|
todo |
Add ability to set redirect manually to better cope with frontend usage. |
package |
Joomla CMS |
Methods
__construct
Constructor.
__construct(mixed||string|int config = [], \Joomla\CMS\MVC\Factory\MVCFactoryInterface factory = null, \Joomla\CMS\Application\CMSApplication app = null, \Joomla\Input\Input input = null, \Joomla\CMS\Form\FormFactoryInterface formFactory = null) :
since |
3.0 |
---|
Arguments
- config
array<string|int, mixed>
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
MVCFactoryInterface|null
The factory.- app
CMSApplication|null
The Application for the dispatcher- input
Input|null
Input- formFactory
FormFactoryInterface|null
The form factory.
Response
mixed
add
Method to add a new record.
add() :
since |
1.6 |
---|
Response
bool
True if the record can be added, false if not.
addModelPath
Adds to the stack of model paths in LIFO order.
addModelPath( path, prefix = '') :
since |
3.0 |
---|---|
deprecated |
4.3 will be removed in 6.0 Will be removed without replacement. Get the model through the MVCFactory instead |
Arguments
- path
mixed
The directory (string), or list of directories (array) to add.- prefix
string
A prefix for models
Response
void
addPath
Adds to the search path for templates and resources.
addPath( type, path) :
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( path) :
since |
3.0 |
---|
Arguments
- path
mixed
The directory (string) or list of directories (array) to add.
Response
static
This object to support chaining.
allowAdd
Method to check if you can add a new record.
allowAdd(mixed||string|int data = []) :
Extended classes can override this if necessary.
since |
1.6 |
---|
Arguments
- data
array<string|int, mixed>
An array of input data.
Response
bool
allowEdit
Method to check if you can edit an existing record.
allowEdit(mixed||string|int data = [], key = 'id') :
Extended classes can override this if necessary.
since |
1.6 |
---|
Arguments
- data
array<string|int, mixed>
An array of input data.- key
string
The name of the key for the primary key; default is id.
Response
bool
allowSave
Method to check if you can save a new or existing record.
allowSave(mixed||string|int data, key = 'id') :
Extended classes can override this if necessary.
since |
1.6 |
---|
Arguments
- data
array<string|int, mixed>
An array of input data.- key
string
The name of the key for the primary key.
Response
bool
batch
Method to run batch operations.
batch(\Joomla\CMS\MVC\Model\BaseDatabaseModel model) :
since |
1.7 |
---|
Arguments
- model
BaseDatabaseModel
The model of the component being processed.
Response
bool
True if successful, false otherwise and internal error is set.
cancel
Method to cancel an edit.
cancel( key = null) :
since |
1.6 |
---|
Arguments
- key
string
The name of the primary key of the URL variable.
Response
bool
True if access level checks pass, false otherwise.
checkEditId
Method to check whether an ID is in the edit list.
checkEditId( context, id) :
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( method = 'post', redirect = true) :
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( type, mixed||string|int parts = []) :
since |
3.0 |
---|
Arguments
- type
string
The resource type to create the filename for.- parts
array<string|int, mixed>
An associative array of filename information. Optional.
Response
string
The filename.
createModel
Method to load and return a model object.
createModel( name, prefix = '', mixed||string|int config = []) : \Joomla\CMS\MVC\Model\BaseDatabaseModel|bool
since |
3.0 |
---|
Arguments
- name
string
The name of the model.- prefix
string
Optional model prefix.- config
array<string|int, mixed>
Configuration array for the model. Optional.
Response
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( name, prefix = '', type = '', mixed||string|int config = []) : \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<string|int, mixed>
Configuration array for the view. Optional.
Response
ViewInterface|null
View object on success; null or error result on failure.
display
Typical view method for MVC based architecture
display( cachable = false, mixed||string|int urlparams = []) :
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<string|int, mixed>
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.
edit
Method to edit an existing record.
edit( key = null, urlVar = null) :
since |
1.6 |
---|
Arguments
- key
string
The name of the primary key of the URL variable.- urlVar
string
The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
Response
bool
True if access level check and checkout passes, false otherwise.
editAssociations
Load item to edit associations in com_associations
editAssociations() :
since |
3.9.0 |
---|---|
deprecated |
4.3 will be removed in 6.0 It is handled by regular save method now. |
Response
void
execute
Execute a task by triggering a method in the derived class.
execute( task) :
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.
getDispatcher
Get the event dispatcher.
getDispatcher() : \Joomla\Event\DispatcherInterface
The override was made to keep a backward compatibility for legacy component. TODO: Remove the override in 6.0
since |
4.4.0 |
---|---|
throws |
|
Response
DispatcherInterface
getFormFactory
Get the FormFactoryInterface.
getFormFactory() : \Joomla\CMS\Form\FormFactoryInterface
since |
4.0.0 |
---|---|
throws |
|
Response
getInstance
Method to get a singleton controller instance.
getInstance( prefix, mixed||string|int config = []) :
since |
3.0 |
---|---|
deprecated |
4.3 will be removed in 6.0 Get the controller through the MVCFactory instead Example: Factory::getApplication()->bootComponent($option)->getMVCFactory()->createController(...); |
throws |
|
Arguments
- prefix
string
The prefix for the controller.- config
array<string|int, mixed>
An array of optional constructor options.
Response
static
getModel
Method to get a model object, loading it if required.
getModel( name = '', prefix = '', mixed||string|int config = ['ignore_request' => true]) : \Joomla\CMS\MVC\Model\BaseDatabaseModel
since |
1.6 |
---|
Arguments
- name
string
The model name. Optional.- prefix
string
The class prefix. Optional.- config
array<string|int, mixed>
Configuration array for model. Optional.
Response
BaseDatabaseModel
The model.
getName
Method to get the controller name
getName() :
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
getRedirectToItemAppend
Gets the URL arguments to append to an item redirect.
getRedirectToItemAppend( recordId = null, urlVar = 'id') :
since |
1.6 |
---|
Arguments
- recordId
int
The primary key id for the item.- urlVar
string
The name of the URL variable for the id.
Response
string
The arguments to append to the redirect URL.
getRedirectToListAppend
Gets the URL arguments to append to a list redirect.
getRedirectToListAppend() :
since |
1.6 |
---|
Response
string
The arguments to append to the redirect URL.
getTask
Get the last task that is being performed or was most recently performed.
getTask() :
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() : mixed||string|int
since |
3.0 |
---|
Response
array<string|int, mixed>
Array[i] of task names.
getView
Method to get a reference to the current view and load it if necessary.
getView( name = '', type = '', prefix = '', mixed||string|int config = []) : \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<string|int, mixed>
Configuration array for view. Optional.
Response
ViewInterface
Reference to the view or an error.
holdEditId
Method to add a record ID to the edit list.
holdEditId( context, id) :
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
void
postSaveHook
Function that allows child controller access to model data after the data has been saved.
postSaveHook(\Joomla\CMS\MVC\Model\BaseDatabaseModel model, mixed||string|int validData = []) :
since |
1.6 |
---|
Arguments
- model
BaseDatabaseModel
The data model object.- validData
array<string|int, mixed>
The validated data.
Response
void
redirect
Redirects the browser or returns false if no redirect is set.
redirect() :
since |
3.0 |
---|
Response
bool
False if no redirect exists.
registerDefaultTask
Register the default task to perform if a mapping is not found.
registerDefaultTask( method) :
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( task, method) :
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( context, id) :
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
void
reload
Method to reload a record.
reload( key = null, urlVar = null) :
since |
3.7.4 |
---|
Arguments
- key
string
The name of the primary key of the URL variable.- urlVar
string
The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
Response
void
save
Method to save a record.
save( key = null, urlVar = null) :
since |
1.6 |
---|
Arguments
- key
string
The name of the primary key of the URL variable.- urlVar
string
The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
Response
bool
True if successful, false otherwise.
setFormFactory
Set the form factory to use.
setFormFactory(\Joomla\CMS\Form\FormFactoryInterface formFactory = null) :
setMessage
Sets the internal message that is passed with a redirect
setMessage( text, type = 'message') :
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( type, path) :
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.
Response
void
setRedirect
Set a URL for browser redirection.
setRedirect( url, msg = null, type = null) :
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( task) :
since |
3.0 |
---|
Arguments
- task
string
The task.
Response
static
This object to support chaining.
Properties
basePath
The base path of the controller
since |
3.0 |
---|
Type(s)
string
default_view
The default view for the display method.
since |
3.0 |
---|
Type(s)
string
doTask
The mapped task that was performed.
since |
3.0 |
---|
Type(s)
string
message
Redirect message.
since |
3.0 |
---|
Type(s)
string
messageType
Redirect message type.
since |
3.0 |
---|
Type(s)
string
methods
Array of class methods
since |
3.0 |
---|
Type(s)
array<string|int, mixed>
name
The name of the controller
since |
3.0 |
---|
Type(s)
string
model_prefix
The prefix of the models
since |
3.0 |
---|
Type(s)
string
paths
The set of search directories for resources (views).
since |
3.0 |
---|
Type(s)
array<string|int, mixed>
redirect
URL for redirection.
since |
3.0 |
---|
Type(s)
string
task
Current or most recently performed task.
since |
3.0 |
---|
Type(s)
string
taskMap
Array of class methods to call for a given task.
since |
3.0 |
---|
Type(s)
array<string|int, mixed>
input
Hold a JInput object for easier access to the input variables.
since |
3.0 |
---|
Type(s)
Input
instance
Instance container.
since |
3.0 |
---|
Type(s)
static
views
Instance container containing the views.
context
The context for storing internal data, e.g. record.
since |
1.6 |
---|
Type(s)
string
option
The URL option for the component.
since |
1.6 |
---|
Type(s)
string
view_item
The URL view item variable.
since |
1.6 |
---|
Type(s)
string
view_list
The URL view list variable.
since |
1.6 |
---|
Type(s)
string
text_prefix
The prefix to use with controller messages.
since |
1.6 |
---|
Type(s)
string