php – Symfony2嵌入式表单和MongoDB问题
|
我尝试将一个表单类型嵌入另一个表单类型: $builder->add('geolocation',new GeolocationType());
但是当我尝试绑定请求到表单 if($request->getMethod() == 'POST') {
$form->bindRequest($request);
}
我得到错误
data_class是为PlaceType和GeolocationType设置的 这是我的代码: Place.php namespace CompanyStoreBundleDocument;
use DoctrineODMMongoDBMappingAnnotations as MongoDB;
/**
* @MongoDBDocument(collection="places")
*/
class Place
{
/**
* @MongoDBId
*/
private $id;
/**
* @MongoDBString
*/
private $title;
/**
* @MongoDBEmbedOne(targetDocument="Geolocation")
*/
private $geolocation;
/**
* Get id
*
* @return id $id
*/
public function getId()
{
return $this->id;
}
/**
* Set geolocation
*
* @param CompanyStoreBundleDocumentGeolocation $geolocation
*/
public function setGeolocation(CompanyStoreBundleDocumentGeolocation $geolocation)
{
$this->geolocation = $geolocation;
}
/**
* Get geolocation
*
* @return CompanyStoreBundleDocumentGeolocation $geolocation
*/
public function getGeolocation()
{
return $this->geolocation;
}
/**
* Set title
*
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get title
*
* @return string $title
*/
public function getTitle()
{
return $this->title;
}
}
Geolocation.php namespace CompanyStoreBundleDocument;
use DoctrineODMMongoDBMappingAnnotations as MongoDB;
/**
* @MongoDBEmbeddedDocument
*/
class Geolocation
{
/**
* @MongoDBId
*/
private $id;
/**
* @MongoDBFloat
*/
private $latitude;
/**
* @MongoDBFloat
*/
private $longitude;
/**
* Get id
*
* @return id $id
*/
public function getId()
{
return $this->id;
}
/**
* Set latitude
*
* @param float $latitude
*/
public function setLatitude($latitude)
{
$this->latitude = $latitude;
}
/**
* Get latitude
*
* @return float $latitude
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* Set longitude
*
* @param float $longitude
*/
public function setLongitude($longitude)
{
$this->longitude = $longitude;
}
/**
* Get longitude
*
* @return float $longitude
*/
public function getLongitude()
{
return $this->longitude;
}
}
PlaceType.php namespace CompanyAdminBundleFormType;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilder;
use CompanyAdminBundleFormTypeGeolocationType;
class PlaceType extends AbstractType
{
public function buildForm(FormBuilder $builder,array $options)
{
$builder->add('title');
$builder->add('geolocation',new GeolocationType());
}
public function getName()
{
return 'place';
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'CompanyStoreBundleDocumentPlace',);
}
}
GeolocationType.php namespace CompanyAdminBundleFormType;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilder;
class GeolocationType extends AbstractType
{
public function buildForm(FormBuilder $builder,array $options)
{
$builder
->add('latitude')
->add('longitude');
}
public function getDefaultOptions(array $options)
{
return array('data_class' => 'CompanyStoreBundleDocumentGeolocation');
}
public function getName()
{
return 'geolocation';
}
}
谢谢你们 在这种情况下,我觉得你不应该在你的setter方法中使用依赖关系所以代替: setGeolocation(CompanyStoreBundleDocumentGeolocation $geolocation) 尝试这样看看它是否正常工作: setGeolocation($geolocation) (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
