After checking this post, I know that Joomla use task=X.Y
to call the controller to handle the request.
But if I click NEW button on com_categories component, it will access the URL of /administrator/index.php?option=com_categories&view=items
and containing the POST data as below:
Then the URL get redirected to /administrator/index.php?option=com_categories&view=item&layout=edit
.
My question is why the URL /administrator/index.php?option=com_categories&view=items
don't have the task=X.Y
and it can redirect to /administrator/index.php?option=com_categories&view=item&layout=edit
?
I know that it contains the POST data with task=item.add
, but which controller convert this POST data to the destination URL and get redirected to that?
Thanks.
Actually (on 2.5.14), when you click on the "New" button in the Category Manger view, the first request generates a POST:
POST /administrator/index.php?option=com_categories&view=categories HTTP/1.1
POST
requests usually send query strings in the HTTP
message body not just in the URL, in this case the POST
request has the following form data in the body:
filter_search
filter_level
filter_published
filter_access
filter_language
limit 5
limitstart 0
order[] 1
order[] 1
order[] 1
order[] 1
order[] 2
batch[assetgroup_id]
batch[language_id]
batch[category_id]
batch[move_copy] m
extension com_content
task category.add
boxchecked 0
filter_order a.lft
filter_order_Dir asc
original_order_values 1,1,1,1,2
796194955f38a0d8db484c92d92ca5ce 1
You will notice this has a task
parameter that has the value category.add
(not item.add), this is taken into account by the JController
class when getInstance($prefix, $config)
is called in the com_categories
entry point file:
$controller = JControllerLegacy::getInstance('Categories');
The JController
class converts category.add
into a $type
of category
and a $task
of add
. The $type
value is used to assemble the path to the controller in conjunction with the components base path ( in this case /pathto/site/administrator/components/com_categories
).
So, when the instantiated JController
class receives the ->execute($task)
message in com_categories/categories.php
entry point file:
$controller->execute(JRequest::getVar('task'));
it's actually already a controller of type CategoriesControllerCategory
which is the what you would expect to handle the New
button request.