No Code Attached Yet
avatar johnyboom
johnyboom
8 Sep 2023

Steps to reproduce the issue

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();

Expected result

SearchModel should receive $params from component com_finder (based on example)

Actual result

SearchModel receives $params from component com_content (based on example)

System information (as much as possible)

Joomla 4.3

avatar johnyboom johnyboom - open - 8 Sep 2023
avatar johnyboom johnyboom - change - 8 Sep 2023
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 8 Sep 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 8 Sep 2023
avatar johnyboom johnyboom - change - 8 Sep 2023
The description was changed
avatar johnyboom johnyboom - edited - 8 Sep 2023
avatar Hackwar Hackwar - close - 28 Mar 2024
avatar Hackwar
Hackwar - comment - 28 Mar 2024

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.

$searchModel = $app
	->bootComponent('com_finder')
	->getMVCFactory()
	->createModel('Search', 'Site', ['ignore_request' => true]);
avatar Hackwar Hackwar - change - 28 Mar 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-03-28 08:07:40
Closed_By Hackwar

Add a Comment

Login with GitHub to post a comment