【问题标题】:PHP Warning: class_parents(): object or string expectedPHP 警告:class_parents(): object or string expected
【发布时间】:2019-03-27 13:07:59
【问题描述】:

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


}

你能告诉我有什么问题吗?

【问题讨论】:

  • 相关代码在extbase扩展中,来自核心。我还应该插入包含超过 700 行代码的相关 datamapper.php 吗?

标签: typo3 extbase datamapper


【解决方案1】:

找到了解决办法。

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

所以我从这里更改了每个属性

protected $street = '';

到这里

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

【讨论】:

    【解决方案2】:
    class_parents(new $propertyData['type']))) 
    

    你应该为对象使用 new 关键字

    在第 284 行...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-11
      • 2018-07-21
      • 2016-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-14
      • 1970-01-01
      相关资源
      最近更新 更多