ApiController

Extends BaseController

Base class for a Joomla API Controller

Controller (controllers are where you put all the actual code) Provides basic functionality, such as rendering views (aka displaying templates).

since

4.0.0

package

Application

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
inherited
since

3.0

Arguments

config

arrayAn 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\MVCFactoryInterfaceThe factory.

app

\Joomla\CMS\Application\CMSApplicationThe Application for the dispatcher

input

\Joomla\Input\InputInput

Response

mixed

add

Method to add a new record.

add() : void
since

4.0.0

throws

\Joomla\CMS\Access\Exception\NotAllowed

\RuntimeException

addModelPath

Adds to the stack of model paths in LIFO order.

addModelPath(mixed path, string prefix = '') : void
inherited static deprecated
since

3.0

deprecated

5.0 See \Joomla\CMS\MVC\Model\LegacyModelLoaderTrait::getInstance

Arguments

path

mixedThe directory (string), or list of directories (array) to add.

prefix

stringA prefix for models

addPath

Adds to the search path for templates and resources.

addPath(string type, mixed path) : static
inherited
since

3.0

Arguments

type

stringThe path type (e.g. 'model', 'view').

path

mixedThe directory string or stream array to search.

Response

staticA \JControllerLegacy object to support chaining.

addViewPath

Add one or more view paths to the controller's stack, in LIFO order.

addViewPath(mixed path) : static
inherited
since

3.0

Arguments

path

mixedThe directory (string) or list of directories (array) to add.

Response

staticThis object to support chaining.

allowAdd

Method to check if you can add a new record.

allowAdd(array data = array()) : bool

Extended classes can override this if necessary.

since

4.0.0

Arguments

data

arrayAn array of input data.

Response

bool

allowEdit

Method to check if you can edit an existing record.

allowEdit(array data = array(), string key = 'id') : bool

Extended classes can override this if necessary.

since

4.0.0

Arguments

data

arrayAn array of input data.

key

stringThe name of the key for the primary key; default is id.

Response

bool

checkEditId

Method to check whether an ID is in the edit list.

checkEditId(string context, int id) : bool
inherited
since

3.0

Arguments

context

stringThe context for the session storage.

id

intThe ID of the record to add to the edit list.

Response

boolTrue 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
inherited

Use in conjunction with HTMLHelper::_('form.token') or Session::getFormToken.

since

3.7.0

see Session::checkToken()

Arguments

method

stringThe request method in which to look for the token key.

redirect

boolWhether to implicitly redirect user to the referrer page on failure or simply return false.

Response

boolTrue 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
inherited static
since

3.0

Arguments

type

stringThe resource type to create the filename for.

parts

arrayAn associative array of filename information. Optional.

Response

stringThe filename.

createModel

Method to load and return a model object.

createModel(string name, string prefix = '', array config = array()) : \Joomla\CMS\MVC\Model\BaseDatabaseModel|bool
inherited
since

3.0

Arguments

name

stringThe name of the model.

prefix

stringOptional model prefix.

config

arrayConfiguration array for the model. Optional.

Response

\Joomla\CMS\MVC\Model\BaseDatabaseModel|boolModel 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
inherited

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

\Exception

Arguments

name

stringThe name of the view.

prefix

stringOptional prefix for the view class name.

type

stringThe type of view.

config

arrayConfiguration array for the view. Optional.

Response

\Joomla\CMS\MVC\View\ViewInterface|nullView object on success; null or error result on failure.

delete

Removes an item.

delete(int id = null) : void
since

4.0.0

Arguments

id

intThe primary key to delete item.

display

Typical view method for MVC based architecture

display(bool cachable = false, array urlparams = array()) : static
inherited

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

\Exception

Arguments

cachable

boolIf true, the view output will be cached

urlparams

arrayAn array of safe url parameters and their variable types, for valid values see {@link}.

Response

staticA \JControllerLegacy object to support chaining.

displayItem

Basic display of an item view

displayItem(int id = null) : static
since

4.0.0

Arguments

id

intThe primary key to display. Leave empty if you want to retrieve data from the request

Response

staticA \JControllerLegacy object to support chaining.

displayList

Basic display of a list view

displayList() : static
since

4.0.0

Response

staticA \JControllerLegacy object to support chaining.

edit

Method to edit an existing record.

edit() : static
since

4.0.0

Response

staticA \JControllerLegacy object to support chaining.

execute

Execute a task by triggering a method in the derived class.

execute(string task) : mixed
inherited
since

3.0

throws

\Exception

Arguments

task

stringThe task to perform. If no matching task is found, the '__default' task is executed, if defined.

Response

mixedThe value returned by the called method.

getInstance

Method to get a singleton controller instance.

getInstance(string prefix, array config = array()) : static
inherited static deprecated
since

3.0

deprecated

5.0 Get the controller through the MVCFactory instead

throws

\Exceptionif the controller cannot be loaded.

Arguments

prefix

stringThe prefix for the controller.

config

arrayAn 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
inherited
since

3.0

Arguments

name

stringThe model name. Optional.

prefix

stringThe class prefix. Optional.

config

arrayConfiguration array for model. Optional.

Response

\Joomla\CMS\MVC\Model\BaseDatabaseModel|boolModel object on success; otherwise false on failure.

getName

Method to get the controller name

getName() : string
inherited

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

\Exception

Response

stringThe name of the dispatcher

getTask

Get the last task that is being performed or was most recently performed.

getTask() : string
inherited
since

3.0

Response

stringThe task that is being performed or was most recently performed.

getTasks

Gets the available tasks in the controller.

getTasks() : array
inherited
since

3.0

Response

arrayArray[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
inherited
since

3.0

throws

\Exception

Arguments

name

stringThe view name. Optional, defaults to the controller name.

type

stringThe view type. Optional.

prefix

stringThe class prefix. Optional.

config

arrayConfiguration array for view. Optional.

Response

\Joomla\CMS\MVC\View\ViewInterfaceReference to the view or an error.

holdEditId

Method to add a record ID to the edit list.

holdEditId(string context, int id) : void
inherited
since

3.0

Arguments

context

stringThe context for the session storage.

id

intThe ID of the record to add to the edit list.

preprocessSaveData

Method to allow extended classes to manipulate the data to be saved for an extension.

preprocessSaveData(array data) : array
since

4.0.0

Arguments

data

arrayAn array of input data.

Response

array

redirect

Redirects the browser or returns false if no redirect is set.

redirect() : bool
inherited
since

3.0

Response

boolFalse if no redirect exists.

registerDefaultTask

Register the default task to perform if a mapping is not found.

registerDefaultTask(string method) : static
inherited
since

3.0

Arguments

method

stringThe name of the method in the derived class to perform if a named task is not found.

Response

staticA \JControllerLegacy object to support chaining.

registerTask

Register (map) a task to a method in the class.

registerTask(string task, string method) : static
inherited
since

3.0

Arguments

task

stringThe task.

method

stringThe name of the method in the derived class to perform for this task.

Response

staticA \JControllerLegacy object to support chaining.

releaseEditId

Method to check whether an ID is in the edit list.

releaseEditId(string context, int id) : void
inherited
since

3.0

Arguments

context

stringThe context for the session storage.

id

intThe ID of the record to add to the edit list.

save

Method to save a record.

save(int recordKey = null) : int
since

4.0.0

Arguments

recordKey

intThe primary key of the item (if exists)

Response

intThe record ID on success, false on failure

setMessage

Sets the internal message that is passed with a redirect

setMessage(string text, string type = 'message') : string
inherited
since

3.0

Arguments

text

stringMessage to display on redirect.

type

stringMessage type. Optional, defaults to 'message'.

Response

stringPrevious message

setPath

Sets an entire array of search paths for resources.

setPath(string type, string path) : void
inherited
since

3.0

Arguments

type

stringThe type of path to set, typically 'view' or 'model'.

path

stringThe 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
inherited
since

3.0

Arguments

url

stringURL to redirect to.

msg

stringMessage to display on redirect. Optional, defaults to value set internally by controller, if any.

type

stringMessage type. Optional, defaults to 'message' or the type set by a previous call to setMessage.

Response

staticThis object to support chaining.

unregisterTask

Unregister (unmap) a task in the class.

unregisterTask(string task) : static
inherited
since

3.0

Arguments

task

stringThe task.

Response

staticThis object to support chaining.

Properties

contentType

The content type of the item.

since

4.0.0

Type(s)

string

option

The URL option for the component.

since

4.0.0

Type(s)

string

text_prefix

The prefix to use with controller messages.

since

4.0.0

Type(s)

string

context

The context for storing internal data, e.g. record.

since

4.0.0

Type(s)

string

itemsPerPage

Items on a page

Type(s)

int

modelState

The model state to inject

Type(s)

CMSObject

basePath

The base path of the controller

inherited
since

3.0

Type(s)

string

default_view

The default view for the display method.

inherited
since

3.0

Type(s)

string

doTask

The mapped task that was performed.

inherited
since

3.0

Type(s)

string

message

Redirect message.

inherited
since

3.0

Type(s)

string

messageType

Redirect message type.

inherited
since

3.0

Type(s)

string

methods

Array of class methods

inherited
since

3.0

Type(s)

array

name

The name of the controller

inherited
since

3.0

Type(s)

array

model_prefix

The prefix of the models

inherited
since

3.0

Type(s)

string

paths

The set of search directories for resources (views).

inherited
since

3.0

Type(s)

array

redirect

URL for redirection.

inherited
since

3.0

Type(s)

string

task

Current or most recently performed task.

inherited
since

3.0

Type(s)

string

taskMap

Array of class methods to call for a given task.

inherited
since

3.0

Type(s)

array

input

Hold a JInput object for easier access to the input variables.

inherited
since

3.0

Type(s)

\Joomla\Input\Input

factory

The factory.

inherited
since

3.10.0

Type(s)

MVCFactoryInterface

instance

Instance container.

inherited static
since

3.0

Type(s)

static

views

Instance container containing the views.

inherited static
since

3.4

Type(s)

ViewInterface[]

app

The Application

inherited
since

4.0.0

Type(s)

CMSApplication|null