Joomla 4:调用布尔值的成员函数 setState()

Joomla 4: Call to a member function setState() on boolean

我正在准备我的模块之一 运行 使用 Joomla 4,使用夜间构建。我遇到了 3.9 没有的问题。我在文章模型上调用函数 setState 并得到以下异常:

"Call to a member function setState() on boolean"

$appParams 不为空或任何内容。代码也列在下面,异常发生的那一行被标出来了。

// Get an instance of the generic articles model
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); // This returns false instead of the model!

// Set application parameters in model
$app       = JFactory::getApplication();
$appParams = $app->getParams();
$model->setState('params', $appParams);

// Set the filters based on the module params
$model->setState('filter.published', 1);
$model->setState('filter.article_id', $articleIds);
$model->setState('filter.category_id', $params['eventlist_categories']);

我是否监督了一些已弃用的功能?感谢您的帮助!

--- 编辑 ---

我发现 JModelLegacy::getInstance() returns 错误 - 所以可能有一种新方法可以在 Joomla 中获取文章模型! 4 对吧?

对不起,之前我给了你一个例子,我不小心只在 Joomla 3.9 中测试过,后来我意识到它在 Joomla 4 中不再有效。所以现在这是我刚刚的工作版本现在在 Joomla 4 中测试:

$model = $app->bootComponent('com_content')->getMVCFactory()->createModel('Articles', 'Administrator', ['ignore_request' => true]);

显然'Administrator'可以改成'Site',看我们要用什么型号了

在 Joomla 4 中,似乎必须使用 MVCFactoryInterface 来创建和使用模型实例。