If model is created using factory then in many 'populateState' methods are parameters received without component name which results in misconfiguration of the model object.
// some model class
protected function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
$params = $app->getParams();
}
If model is created inside plugin or basically outside models component then received $params are from current component not from models component.
someurl.com/index.php?option=com_content
/** @var SearchModel $searchModel */
$searchModel = $app
->bootComponent('com_finder')
->getMVCFactory()
->createModel('Search', 'Site');
$searchModel->getState(); // SearchModel receives $params from component com_content but should receive $params from com_finder
$searchModel->getQuery();
$items = $searchModel->getItems();
SearchModel should receive $params from component com_finder (based on example)
SearchModel receives $params from component com_content (based on example)
Joomla 4.3
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-03-28 08:07:40 |
Closed_By | ⇒ | Hackwar |
This is not a bug, but expected behavior. The model retrieves the configuration from the current request, as long as you don't tell it to do otherwise. If you want to set your own configuration, you have to add the option
ignore_request => true
to the invocation.