2013-08-30

More updates to remove deprecated code/joomla versions

← Older revision

Revision as of 12:32, 30 August 2013

Line 20:

Line 20:

 

</source>

 

</source>

 

 



Now that you have controller.php included and the base
JController
class imported, you have to define a class that extends the
JController
base class. This is the class leg you wrote before about and it is here where your action will happen. You can name this class as you like but, by convention, it is named after your component so you write:

+

Now that you have controller.php included and the base
JControllerLegacy
class imported, you have to define a class that extends the
JControllerLegacy
base class. This is the class leg you wrote before about and it is here where your action will happen. You can name this class as you like but, by convention, it is named after your component so you write:

 

 

 

<source lang="php">

 

<source lang="php">



class <name>Controller extends
JController

+

class <name>Controller extends
JControllerLegacy

 

{

 

{

 

}

 

}

Line 32:

Line 32:

 

<source lang="php">

 

<source lang="php">

 

// Get an instance of the controller prefixed by <name>

 

// Get an instance of the controller prefixed by <name>



$controller =
JController
::getInstance('<name>');

+

$controller =
JControllerLegacy
::getInstance('<name>');

 

 

 

// Perform the Request task

 

// Perform the Request task

Line 38:

Line 38:

 

 

 

// Redirect if set by the controller

 

// Redirect if set by the controller



$controller->redirect();
</source>

+

$controller->redirect();

 

</source>

 

</source>

 

 

Line 50:

Line 50:

 

 

 

<source lang="php">

 

<source lang="php">



class <name>Controller extends
JControllerLegay

+

class <name>Controller extends
JControllerLegacy

 

 

 

{

 

{

Line 65:

Line 65:

 

<source lang="php">

 

<source lang="php">

 

 



class <name>Controller extends
JController

+

class <name>Controller extends
JControllerLegacy

 

{

 

{

 

   function jump()

 

   function jump()

Line 75:

Line 75:

 

</source>

 

</source>

 

 



Up to now you have delved with the controller part of the model. This is a new point of decision. You can stop here or go a step further and enter the view part
. Stopping here will, at least, simplify your base file over Joomla! 1.1.x . Up to version 1.5, components usually had a switch statement that, depending on the given task (or whatever passed variable), called a function with several arguments to deliver the HTML result
.

+

Up to now you have delved with the controller part of the model. This is a new point of decision. You can stop here or go a step further and enter the view part.

 

 



With Joomla! 1.5, the switch is gone and your
different tasks are methods in the controller.php file.
Arguments are lost but all
the needed variables are available from the Platform so you will be able to retrieve them easily.

+

The
different tasks
given to the controller
are methods in the controller.php file.
All
the needed variables are available from the Platform so you will be able to retrieve them easily.

 

 

 

There is nothing that forces you to use the 'task' variable to drive the call because you can pass the value of any variable as the parameter to the execute method call. But in order to stick to the non-written rules, 'task' is usually used (and as it is treated specially by the system, it is a good idea to stick with it).

 

There is nothing that forces you to use the 'task' variable to drive the call because you can pass the value of any variable as the parameter to the execute method call. But in order to stick to the non-written rules, 'task' is usually used (and as it is treated specially by the system, it is a good idea to stick with it).

 

 



To trigger the views, you have to call the
display
() method of
JController
. Do this by inserting, in your method, a call to parent::
display
() as in the last line. At a minimum, your controller file should contain the following:  

+

To trigger the views, you have to call the
__construct
() method of
JControllerLegacy
. Do this by inserting, in your method, a call to parent::
__construct
() as in the last line. At a minimum, your controller file should contain the following:  

 

 

 

<source lang="php">

 

<source lang="php">

Line 87:

Line 87:

 

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

 

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

 

 



class <name>Controller extends
JController

+

class <name>Controller extends
JControllerLegacy

 

{

 

{



   function
display
()

+

  
public
function
__construct
(
$config = array()
)

 

   {

 

   {



     parent::
display
();

+

     parent::
__construct
(
$config
);

 

   }

 

   }

 

}

 

}



 

 

</source>

 

</source>

 

 

Line 152:

Line 151:

 

Can you have other functions besides display? I don't know. This is something that the gurus must answer. Where does the display function come from? Again, I don't know. Hope that someone else can help here.

 

Can you have other functions besides display? I don't know. This is something that the gurus must answer. Where does the display function come from? Again, I don't know. Hope that someone else can help here.

 

 



But you can go a bit further. Up to this point you have a distributed Platform that dissects your request in such a way that allow you to create small and very specific files to react only to specific types of requests. In this way the files that you must process can be very small and adjusted to the situation you are treating, speeding up the global response time of the system by not loading lots of code that will not ever be used with this kind of requests
(as in Joomla! 1.x)
.

+

But you can go a bit further. Up to this point you have a distributed Platform that dissects your request in such a way that allow you to create small and very specific files to react only to specific types of requests. In this way the files that you must process can be very small and adjusted to the situation you are treating, speeding up the global response time of the system by not loading lots of code that will not ever be used with this kind of requests.

 

 

 

Having reached this point you can dissect a bit more and have another layer of detail: the final layout for the data you deliver.

 

Having reached this point you can dissect a bit more and have another layer of detail: the final layout for the data you deliver.

Show more