Extbase对象的属性在FLUID中返回NULL,但仅当直接调用时

时间:2019-06-18 09:15:46

标签: typo3

我面临一个非常奇怪的问题:在FLUID中调试具有所有属性的对象时,将显示该属性。尝试直接调用某些属性时,它们会显示其值。但是在某些属性上,该值为NULL,但仅当直接调用时才为。 例如{addresses.0.lastname}显示姓氏,但是{addresses.0.lng}不显示“ lng”的值,尽管在调用{addresses}时有一个值!?

ext_tables.sql:

    CREATE TABLE tx_pngooglemap_domain_model_address (
        uid int(11) NOT NULL auto_increment,
        ....
        firstname varchar(255) DEFAULT '' NOT NULL,
        lastname varchar(255) DEFAULT '' NOT NULL,
        ....
        lat varchar(255) DEFAULT '' NOT NULL,
        lng varchar(255) DEFAULT '' NOT NULL,
        notes text DEFAULT '' NOT NULL,

型号:

    class Address extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
    {    
    /**
     * firstname
     *
     * @var string
     * @validate NotEmpty
     */
    protected $firstname = '';

    /**
     * lastname
     *
     * @var string
     * @validate NotEmpty
     */
    protected $lastname = '';

    /******************* some more properties ***/

    /**
     * lat
     *
     * @var string
     * @validate NotEmpty
     */
    protected $lat = '';

    /**
     * lng
     *
     * @var string
     * @validate NotEmpty
     */
    protected $lng = '';


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

    /**
     * Sets the firstname
     *
     * @param string $firstname
     * @return void
     */
    public function setFirstname($firstname)
    {
        $this->firstname = $firstname;
    }

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

    /**
     * Sets the lastname
     *
     * @param string $lastname
     * @return void
     */
    public function setLastname($lastname)
    {
        $this->lastname = $lastname;
    }

    /******************* some more getters and setters for properties ***/

    /**
     * Returns the lat
     *
     * @return string $lat
     */
    public function getLat()
    {
        return $lat->lat;
    }

    /**
     * Sets the lat
     *
     * @param string $lat
     * @return void
     */
    public function setLat($lat)
    {
        $this->lat = $lat;
    }

    /**
     * Returns the lng
     *
     * @return string $lng
     */
    public function getLng()
    {
        return $lng->lng;
    }

    /**
     * Sets the lng
     *
     * @param string $lng
     * @return void
     */
    public function setLng($lng)
    {
        $this->lng = $lng;
    }
    }

tca.php:

    'lastname' => [
        'exclude' => true,
        'label' => 'LLL:EXT:pngooglemap/Resources/Private/Language/locallang_db.xlf:tx_pngooglemap_domain_model_address.lastname',
        'config' => [
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim,required'
        ],
    ],
    'lat' => [
        'exclude' => true,
        'label' => 'LLL:EXT:pngooglemap/Resources/Private/Language/locallang_db.xlf:tx_pngooglemap_domain_model_address.latitude',
        'config' => [
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim'
        ]
    ],
    'lng' => [
        'exclude' => true,
        'label' => 'LLL:EXT:pngooglemap/Resources/Private/Language/locallang_db.xlf:tx_pngooglemap_domain_model_address.longitude',
        'config' => [
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim'
        ]
    ],    

控制器:

public function listAction()
    {    
        $addresses = $this->addressRepository->findAll();
        $this->view->assign('addresses', $addresses);
    }

List.html:

    <html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
    <f:layout name="Default" />

    <f:section name="main">
        <f:debug>{addresses.0}</f:debug> => shows all fields with their values
        <f:debug>{addresses.0.lastname}</f:debug> => shows the lastname
        <f:debug>{addresses.0.lng}</f:debug> => shows "NULL" instead of "48.45673"
    </f:section>
    </html>

1 个答案:

答案 0 :(得分:1)

问题是您的return $lng->lng;函数中的getLng。这应该是return $this->lng;

调试addresses.0会直接显示属性。 addresses.0.lng使用getLng函数。