由于信号槽中缺少对象而出错 (tx_news)

error because of missing object in signalslot (tx_news)

我为 tx_news 编写了一个扩展 detailAction 的信号槽扩展。当调用详细新闻视图时,调度程序按预期工作。但是,当在没有现有新闻条目的有效参数的情况下调用详细信息页面时,我收到以下错误:

Oops, an error occurred!
Argument 1 passed to .....\Slots\NewsControllerSlot::detailActionSlot() must be an instance of GeorgRinger\News\Domain\Model\News, null given

错误很容易理解:

public function detailActionSlot(News $newsItem, $currentPage, $demand, $settings, $extendedVariables)

缺少第一个参数 $newsItem。

但是我怎样才能避免这个错误呢? 谢谢!

在 github 上创建一个 pr 或者至少是一个问题,这是一个错误

David Bruchmann 给了我一个提示:

public function detailActionSlot(News $newsItem = null, $currentPage, $demand, $settings, $extendedVariables)
{
    if (is_object($newsItem)) { 
        // do stuff here
   }
}

即使抛出 404 也能完美运行。