1

The Joomla\CMS\MVC\Controller\FormController::getModel method has a default argument for the config argument that sets the ignore_request parameter to true. This in turn means that models will not call the populateState method.

Why is the FormController, the only controller to prevent populateState being called? What is the reason that you wouldn't want populateState to be called when working with a submitted form?

0

I don't know for sure, but I've thought of a reason why it makes sense, so here goes …

Joomla components use FormController to handle whenever the (usually admin) user is editing an item and then presses eg Save to save the changes. This results in an HTTP POST to the server with the task parameter set, and control gets routed to the appropriate controller php file in the component controllers directory.

The controller needs to get the form loaded in order to validate the POST data, and this involves going to the component model and using it to load the form. During this process the model's getState can be called, and hence populateState.

However, because Joomla uses the Post/Redirect/Get pattern, this HTTP POST is going to end up with an HTTP redirect. The method populateState on the other hand sets up variables which are later used in preparation for outputting data in an HTTP response, and also can involve database queries, eg to get config params. So it's actually doing a lot of work, sometimes involving database queries, for no good reason, as the HTTP response in this case will be a redirect.

Maybe the Joomla team were doing some performance analysis and noticed that there were database queries which were superfluous, tracked them down to populateState and then came up with this ignore_request flag as a generic solution that didn't involve changing each component.

Have I convinced you ;-) ?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.