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
requests usually send query strings in theHTTP
message body not just in the URL, in this case thePOST
request has the following form data in the body:You will notice this has a
task
parameter that has the valuecategory.add
(not item.add), this is taken into account by theJController
class whengetInstance($prefix, $config)
is called in thecom_categories
entry point file:The
JController
class convertscategory.add
into a$type
ofcategory
and a$task
ofadd
. 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 incom_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 theNew
button request.