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

时间:2019-03-27 13:08:00

标签: typo3 extbase datamapper

我正在使用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;
}


}

你能告诉我哪里出问题了吗?

2 个答案:

答案 0 :(得分:1)

找到了解决方案。

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

所以我从此更改了每个属性

protected $street = '';

对此

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

答案 1 :(得分:0)

class_parents(new $propertyData['type']))) 

您应该为对象使用新关键字

第284行...