从 TYPO3 v9 升级到 v10 后:显示页面不再工作(无法访问受保护的属性)

Leh*_*tis 2 typo3 typo3-9.x typo3-10.x

我已经编写了一个基于 TYPO3 版本 9 的扩展。我现在已将其安装在 TYPO3 版本 10 系统中,一切似乎都工作正常。只有显示页面无法再打开。

错误来了:

Cannot access protected property myname\myextension\Domain\Model\Country::$name
Run Code Online (Sandbox Code Playgroud)

我不明白这个错误。在列表页面上我通常使用国家/地区名称。在“显示”页面上我根本不使用它。因此,为什么这会引起问题是没有意义的。

这是我的 Show.html

<div class="card">
    <h5 class="card-header" style="text-align: center">
        {house.name}
    </h5>
    <div class="card-body" style="text-align: center">
        <p class="card-text">
            <f:link.external uri="{house.link}" target="_blank">{house.link}</f:link.external>
        </p>
        <h2>Rooms</h2>
        <ul>
            <f:for each="{house.room}" as="room">
                <li>{room.name}</li>
            </f:for>
        </ul>
    </div>
</div>
<f:link.action action="list" class="btn btn-primary">
    BACK
</f:link.action>
Run Code Online (Sandbox Code Playgroud)

我的控制器

class HouseController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
............
............
    /**
     * @param House $house
     */
    public function showAction(House $house)
    {
        $this->view->assign('house', $house);
    }
Run Code Online (Sandbox Code Playgroud)

正如之前所说,完整的代码在版本 9 上运行良好,在版本 10 中肯定存在一些问题。

编辑:这是我的国家模型

class Country extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{

    /**
     * Country Name
     * 
     * @var string
     * @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
     */
    protected $name = '';

    /**
     * Returns the name
     * 
     * @return string $name
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Sets the name
     * 
     * @param string $name
     * @return void
     */
    public function setName($name)
    {
        $this->name = $name;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的房屋模型(不是所有线路):

class House extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
    /**
     * __construct
     */
     public function __construct()
     {

            //Do not remove the next line: It would break the functionality
            $this->initStorageObjects();
     }
    /**
     * Countrie House
     * 
     * @var \myname\myextension\Domain\Model\Country
     * @TYPO3\CMS\Extbase\Annotation\ORM\Lazy
     */
    protected $country = null;

    /**
     * Returns the country
     * 
     * @return \myname\myextension\Domain\Model\Country $country
     */
    public function getCountry()
    {
        return $this->country;
    }

    /**
     * Sets the country
     * 
     * @param \myname\myextension\Domain\Model\Country $country
     * @return void
     */
    public function setCountry(\myname\myextension\Domain\Model\Country $country)
    {
        $this->country = $country;
    }
}
Run Code Online (Sandbox Code Playgroud)

Tho*_*ler 6

问题是您正在使用@TYPO3\CMS\Extbase\Annotation\ORM\Lazy与模型的直接关系。该@TYPO3\CMS\Extbase\Annotation\ORM\Lazy注解对于使用有帮助ObjectStorage,不建议直接用于其他模型。