PHP警告:class_parents():期望的对象或字符串

问题描述 投票:0回答:2

我正在使用TYPO3,我在我的扩展中有我自己的模型,控制器和存储库文件。在后端我创建了一个没有任何问题的记录。但是当我尝试加载FE时,我在DataMapper.php中收到以下错误

PHP Warning: class_parents(): object or string expected in /home/app/vendor/typo3/cms/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php line 284

00284:  if ($propertyData['type'] === 'DateTime' || in_array('DateTime', class_parents($propertyData['type']))) {

我调试它,发现$ propertyName包含正确的属性名称'street',但$ propertyData是一个空数组。

我的模型看起来像这样:

<?php

namespace Snowflake\Htwapartmentexchange\Domain\Model;

use Snowflake\ApiRepository\Helpers\DateTime;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;


class Apartment extends AbstractEntity
{
protected $apartmentType = '';
protected $street = '';
protected $zip = '';
protected $city = '';
protected $price = '';
protected $countRooms = '';
protected $area = '';
protected $availableDate = '';
protected $description = '';
protected $firstname = '';
protected $lastname = '';
protected $mobile = '';
protected $mail = '';
protected $pictures = null;

/**
 * Apartment constructor.
 * @param $apartmentType
 * @param $street
 * @param $zip
 * @param $city
 * @param $price
 * @param $countRooms
 * @param $area
 * @param $availableDate
 * @param $description
 * @param $firstname
 * @param $lastname
 * @param $mobile
 * @param $mail
 * @param $pictures
 */
public function __construct($apartmentType, $street, $zip, $city, $price, $countRooms, $area, $availableDate, $description, $firstname, $lastname, $mobile, $mail, $pictures)
{
    $this->apartmentType = $apartmentType;
    $this->street = $street;
    $this->zip = $zip;
    $this->city = $city;
    $this->price = $price;
    $this->countRooms = $countRooms;
    $this->area = $area;
    $this->availableDate = $availableDate;
    $this->description = $description;
    $this->firstname = $firstname;
    $this->lastname = $lastname;
    $this->mobile = $mobile;
    $this->mail = $mail;
    $this->pictures = $pictures;
}

/**
 * @return mixed
 */
public function getApartmentType()
{
    return $this->apartmentType;
}

/**
 * @param mixed $apartmentType
 */
public function setApartmentType($apartmentType)
{
    $this->apartmentType = $apartmentType;
}


/**
 * @return mixed
 */
public function getStreet()
{
    return $this->street;
}

/**
 * @param mixed $street
 */
public function setStreet($street)
{
    $this->street = $street;
}

/**
 * @return mixed
 */
public function getZip()
{
    return $this->zip;
}

/**
 * @param mixed $zip
 */
public function setZip($zip)
{
    $this->zip = $zip;
}

/**
 * @return mixed
 */
public function getCity()
{
    return $this->city;
}

/**
 * @param mixed $city
 */
public function setCity($city)
{
    $this->city = $city;
}

/**
 * @return mixed
 */
public function getPrice()
{
    return $this->price;
}

/**
 * @param mixed $price
 */
public function setPrice($price)
{
    $this->price = $price;
}

/**
 * @return mixed
 */
public function getCountRooms()
{
    return $this->countRooms;
}

/**
 * @param mixed $countRooms
 */
public function setCountRooms($countRooms)
{
    $this->countRooms = $countRooms;
}

/**
 * @return mixed
 */
public function getArea()
{
    return $this->area;
}

/**
 * @param mixed $area
 */
public function setArea($area)
{
    $this->area = $area;
}

/**
 * @return DateTime
 */
public function getAvailableDate()
{
    return $this->availableDate;
}

/**
 * @param DateTime $availableDate
 */
public function setAvailableDate($availableDate)
{
    $this->availableDate = $availableDate;
}


/**
 * @return mixed
 */
public function getDescription()
{
    return $this->description;
}

/**
 * @param mixed $description
 */
public function setDescription($description)
{
    $this->description = $description;
}

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

/**
 * @param mixed $firstname
 */
public function setFirstname($firstname)
{
    $this->firstname = $firstname;
}

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

/**
 * @param mixed $lastname
 */
public function setLastname($lastname)
{
    $this->lastname = $lastname;
}

/**
 * @return mixed
 */
public function getMobile()
{
    return $this->mobile;
}

/**
 * @param mixed $mobile
 */
public function setMobile($mobile)
{
    $this->mobile = $mobile;
}

/**
 * @return mixed
 */
public function getMail()
{
    return $this->mail;
}

/**
 * @param mixed $mail
 */
public function setMail($mail)
{
    $this->mail = $mail;
}

/**
 * @return mixed
 */
public function getPictures()
{
    return $this->pictures;
}

/**
 * @param mixed $pictures
 */
public function setPictures($pictures)
{
    $this->pictures = $pictures;
}


}

你能告诉我出了什么问题吗?

typo3 extbase datamapper
2个回答
1
投票

找到了解决方案。

问题是我没有在我的模型上使用PHPDoc注释。

所以我改变了每一个属性

protected $street = '';

对此

/**
 * @var string
 */
protected $street = '';

0
投票
class_parents(new $propertyData['type']))) 

你应该使用对象的新关键字

在284行......

© www.soinside.com 2019 - 2024. All rights reserved.