嗨,我正在尝试从symfony模型中扩展实体。这是我的模特,
<?php
namespace App\Model;
use Doctrine\ORM\Mapping as ORM;
use Swagger\Annotations as SWG;
class BaseCar
{
/**
* @var int
* @SWG\Property(description="The unique identifier of the car.")
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $name;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $code;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Model",cascade={"refresh","merge"}, inversedBy="cars")
* @ORM\JoinColumn(nullable=false)
*/
protected $model;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $year;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $type;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $body_type;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $engine_power;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $fuel;
/**
* @SWG\Property(type="integer")
* @ORM\Column(type="integer", nullable=true)
*/
protected $doors;
/**
* @SWG\Property(type="integer")
* @ORM\Column(type="integer", nullable=true)
*/
protected $seats;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $transmission;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $weigth;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $engine_position;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $engine_type;
/**
* @SWG\Property(type="integer")
* @ORM\Column(type="integer", nullable=true)
*/
protected $cylinders;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $engine_capacity;
/**
* @SWG\Property(type="integer")
* @ORM\Column(type="integer", nullable=true)
*/
protected $valves_per_cylinder;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $fuel_efficiency;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $max_speed;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $fuel_efficiency_min;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $torque;
/**
* @SWG\Property(type="string", maxLength=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $image;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
/**
* @param string $name
* @return \
*/
public function setName(string $name)
{
$this->name = $name;
return $this;
}
public function getCode()
{
return $this->code;
}
/**
* @param string $code
* @return \
*/
public function setCode(string $code)
{
$this->code = $code;
return $this;
}
public function getYear()
{
return $this->year;
}
public function setYear( $year)
{
$this->year = $year;
return $this;
}
public function getType()
{
return $this->type;
}
public /**
* @param $
*/function setType( $type)
{
$this->type = $type;
return $this;
}
public function getBodyType()
{
return $this->body_type;
}
public function setBodyType( $body_type)
{
$this->body_type = $body_type;
return $this;
}
public function getEnginePower()
{
return $this->engine_power;
}
public /**
* @param $
*/function setEnginePower( $engine_power)
{
$this->engine_power = $engine_power;
return $this;
}
public function getFuel()
{
return $this->fuel;
}
public /**
* @param $
*/function setFuel( $fuel)
{
$this->fuel = $fuel;
return $this;
}
public function getDoors()
{
return $this->doors;
}
public /**
* @param $
*/function setDoors( $doors)
{
$this->doors = $doors;
return $this;
}
public function getSeats()
{
return $this->seats;
}
public /**
* @param $
*/function setSeats( $seats)
{
$this->seats = $seats;
return $this;
}
public function getTransmission()
{
return $this->transmission;
}
public /**
* @param $
*/function setTransmission( $transmission)
{
$this->transmission = $transmission;
return $this;
}
public function getWeigth()
{
return $this->weigth;
}
public /**
* @param $
*/function setWeigth( $weigth)
{
$this->weigth = $weigth;
return $this;
}
public function getEnginePosition()
{
return $this->engine_position;
}
public /**
* @param $
*/function setEnginePosition( $engine_position)
{
$this->engine_position = $engine_position;
return $this;
}
public function getEngineType()
{
return $this->engine_type;
}
public /**
* @param $
*/function setEngineType( $engine_type)
{
$this->engine_type = $engine_type;
return $this;
}
public function getCylinders()
{
return $this->cylinders;
}
public /**
* @param $
*/function setCylinders( $cylinders)
{
$this->cylinders = $cylinders;
return $this;
}
public function getEngineCapacity()
{
return $this->engine_capacity;
}
public /**
* @param $
*/function setEngineCapacity( $engine_capacity)
{
$this->engine_capacity = $engine_capacity;
return $this;
}
public function getValvesPerCylinder()
{
return $this->valves_per_cylinder;
}
public /**
* @param $
*/function setValvesPerCylinder( $valves_per_cylinder)
{
$this->valves_per_cylinder = $valves_per_cylinder;
return $this;
}
public function getFuelEfficiency()
{
return $this->fuel_efficiency;
}
public /**
* @param $
*/function setFuelEfficiency( $fuel_efficiency)
{
$this->fuel_efficiency = $fuel_efficiency;
return $this;
}
public function getMaxSpeed()
{
return $this->max_speed;
}
public /**
* @param $
*/function setMaxSpeed( $max_speed)
{
$this->max_speed = $max_speed;
return $this;
}
public function getFuelEfficiencyMin()
{
return $this->fuel_efficiency_min;
}
public /**
* @param $
*/function setFuelEfficiencyMin( $fuel_efficiency_min)
{
$this->fuel_efficiency_min = $fuel_efficiency_min;
return $this;
}
public function getTorque()
{
return $this->torque;
}
public /**
* @param $
*/function setTorque( $torque)
{
$this->torque = $torque;
return $this;
}
public function getImage()
{
return $this->image;
}
public /**
* @param $
*/function setImage( $image)
{
$this->image = $image;
return $this;
}
public function __toString()
{
return $this->getName();
}
}
这是我的实体,
<?php
namespace App\Entity;
use App\Model\BaseCar;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Swagger\Annotations as SWG;
use JMS\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass="App\Repository\CarRepository")
* @UniqueEntity("id")
*/
class Car extends BaseCar
{
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Model",cascade={"refresh","merge"}, inversedBy="cars")
* @ORM\JoinColumn(nullable=false)
*/
protected $model;
public function getModel()
{
return $this->model;
}
public /**
* @param $
*/function setModel( $model)
{
$this->model = $model;
return $this;
}
}
但是当我使用模型时,会出现此错误。
“属性App \ Model \ BaseCar :: $ model不存在”
如果有人可以回答这个问题,那将是很大的帮助。