我尝试将表单类型嵌入到另一种表单类型中:
$builder->add('geolocation', new GeolocationType());
Run Code Online (Sandbox Code Playgroud)
但是当我尝试将请求绑定到表单时
if($request->getMethod() == 'POST') {
$form->bindRequest($request);
}
Run Code Online (Sandbox Code Playgroud)
我收到了错误
可捕获的致命错误:传递给Company\StoreBundle\Document\Place :: setGeolocation()的参数1必须是Company\StoreBundle\Document\Geolocation的实例,给定的数组,在
/var/www/Company/vendor/symfony/src中调用第392行/Symfony/Component/Form/Util/PropertyPath.php,在/var/www/Company/src/Company/StoreBundle/Document/Place.php第43行中定义
该data_class设置无论是对PlaceType和GeolocationType
这是我的代码:
Place.php
namespace Company\StoreBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document(collection="places")
*/
class Place
{
/**
* @MongoDB\Id
*/
private $id;
/**
* @MongoDB\String
*/
private $title;
/**
* @MongoDB\EmbedOne(targetDocument="Geolocation")
*/
private $geolocation;
/**
* Get id
*
* @return id $id
*/
public function getId()
{
return $this->id;
}
/**
* Set geolocation
*
* @param Company\StoreBundle\Document\Geolocation $geolocation
*/
public …Run Code Online (Sandbox Code Playgroud)