API15

JController: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </span> {{Description:JController}} ===Defined in==...
 
m preparing for archive only
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<span class="editsection" style="font-size:76%;">
JController is an abstract class which provides the basic functionality for your own Controller classes which your create for your components. The Controller is part of Joomla's MVC Pattern. [[Developing_a_Model-View-Controller_Component_-_Part_1|Learn how to develop a component using MVC]]
<nowiki>[</nowiki>[[Description:JController|Edit Descripton]]<nowiki>]</nowiki>
 
</span>
===The Joomla MVC Design Pattern===
{{Description:JController}}
Model-View-Controller (MVC) is a set of design patterns, that are used to separate the different layers of your application.
 
* The '''View''' displays the data of the model by passing it to a template. The view object can therefore access the data of the model. Joomla implements the basic functionality in the abstract JView class.
* The '''Model''' stores the data of the application, and contains the business logic. Joomla implements the basic functionality in the abstract JModel class.
* The '''Controller''' handles the user requests and evokes the model and the views to change it's state. Joomla implements the basic functionality in the JController class.


===Defined in===
===Defined in===
Line 11: Line 15:
!Method name
!Method name
!Description
!Description
|-
|[[API15:JController/getInstance|getInstance]]
|Method to get a singleton controller instance.
|-
|[[API15:JController/addModelPath|addModelPath]]
|Adds to the stack of model paths in LIFO order.
|-
|[[API15:JController/addViewPath|addViewPath]]
|Add one or more view paths to the controller's stack, in LIFO order.
|-
|-
|[[API15:JController/__construct|__construct]]
|[[API15:JController/__construct|__construct]]
Line 67: Line 62:
|[[API15:JController/setAccessControl|setAccessControl]]
|[[API15:JController/setAccessControl|setAccessControl]]
|Sets the access control levels.
|Sets the access control levels.
|-
|[[API15:JController/addModelPath|addModelPath]]
|Adds to the stack of model paths in LIFO order.
|-
|[[API15:JController/addViewPath|addViewPath]]
|Add one or more view paths to the controller's stack, in LIFO order.
|}
|}
===Importing===
===Importing===
<source lang="php">jimport( 'joomla.application.component.controller' );</source>
<source lang="php">jimport( 'joomla.application.component.controller' );</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JController|Edit See Also]]<nowiki>]</nowiki>
 
</span>
{{SeeAlso:JController}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=JController
  category=JController
  category=CodeExample
  namespace=CodeExample
  category=ClassExample
  category=ClassExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 00:24, 25 March 2017

JController is an abstract class which provides the basic functionality for your own Controller classes which your create for your components. The Controller is part of Joomla's MVC Pattern. Learn how to develop a component using MVC

The Joomla MVC Design Pattern

Model-View-Controller (MVC) is a set of design patterns, that are used to separate the different layers of your application.

  • The View displays the data of the model by passing it to a template. The view object can therefore access the data of the model. Joomla implements the basic functionality in the abstract JView class.
  • The Model stores the data of the application, and contains the business logic. Joomla implements the basic functionality in the abstract JModel class.
  • The Controller handles the user requests and evokes the model and the views to change it's state. Joomla implements the basic functionality in the JController class.

Defined in

libraries/joomla/application/component/controller.php

Methods

Method name Description
__construct Constructor.
execute Execute a task by triggering a method in the derived class.
authorize Authorization check
display Typical view method for MVC based architecture
redirect Redirects the browser or returns false if no redirect is set.
getModel Method to get a model object, loading it if required.
getTasks Gets the available tasks in the controller. public array Array[i] of task names.

1.5

getTask Get the last task that is or was to be performed.
getName Method to get the controller name
getView Method to get a reference to the current view and load it if necessary.
registerTask Register (map) a task to a method in the class.
registerDefaultTask Register the default task to perform if a mapping is not found.
setMessage Sets the internal message that is passed with a redirect
setRedirect Set a URL for browser redirection.
setAccessControl Sets the access control levels.
addModelPath Adds to the stack of model paths in LIFO order.
addViewPath Add one or more view paths to the controller's stack, in LIFO order.

Importing

jimport( 'joomla.application.component.controller' );



Examples

Code Examples