Reputation: 569
I've been trying to learn how to build a Joomla component.
I've been using http://joomlaprogrammingbook.com/ book which is great. I can now do plugins and modules without too much of a problem. However I'm getting stuck with how certain controllers get loaded for components. The site given has the full code if it's needed.
The initial controller loaded is:
class JoomproSubsController extends JController
{
/**
* @var string The default view.
* @since 1.6
*/
protected $default_view = 'submanager';
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return JController This object to support chaining.
*/
public function display($cachable = false, $urlparams = false)
{
JLoader::register('JoomproSubsHelper', JPATH_COMPONENT.'/helpers/joomprosubs.php');
// Load the submenu.
JoomproSubsHelper::addSubmenu(JRequest::getCmd('view', 'submanager'));
$view = JRequest::getCmd('view', 'submanager');
$layout = JRequest::getCmd('layout', 'default');
$id = JRequest::getInt('id');
// Check for edit form.
if ($view == 'subscription' && $layout == 'edit' && !$this->checkEditId('com_joomprosubs.edit.subscription', $id)) {
// Somehow the person just went to the form - we don't allow that.
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option=com_joomprosubs&view=submanager', false));
return false;
}
parent::display();
return $this;
}
}
I can see how and when this is loaded. However at some point in this it also seems to load class JoomproSubsControllerSubManager extends JControllerAdmin
now I though that to do this it would need a url which included com_joomproSubs?task=submanager
but that doesn't exist. So my question is how can this happen?
Upvotes: 0
Views: 2278
Reputation: 9636
Subcontrollers are used for tasks like new, edit, delete, save and so on for components items as there might be different types of these (banners/ clients/ tracks) having different functionality (item, list, form).
Using an URLs
com_joomprosubs?task=item.display
you execute controller method JoomprosubsControlerItem->display()
in file components/com_joomprosubs/controllers/item.php.
If you'd use
com_joomprosubs?task=submanager
you'd would JoomprosubsController->submanager()
in components/com_joomprosubs/controller.php.
Upvotes: 1
Reputation: 9330
In Joomla! everything passes through index.php
(although in the front-end you won't see index.php
in the URL if the SEF options are turned on).
So the entry points are index.php
or /administrator/index.php
(for the backend). To this are appended some parameters that tell Joomla! how to route the request.
option=X
task=Y.Z
view=V
option
This is the parameter that tells Joomla what component is to handle the request. e.g. option=com_content
for the component that handles standard articles. Subsequent to the component value being determined, Joomla is then expecting everything to be in the matching directory. In our example this will be /components/com_content/
or for the backend /administrator/components/com_content/
task
The task
parameter can take a dot notation value of the form controller.method
e.g. task=article.edit
in the Article Manager. Using the elements of this value Joomla! loads the article.php
file in the /com_content/controllers/
directory and fires the method edit
view
The view
parameter is used to nominate a specific view within the same controller e.g. again in the com_content
component you see these two variations in the value of view:
/administrator/index.php?option=com_content&view=featured
/administrator/index.php?option=com_content&view=articles
Upvotes: 3