4

このバンドルを で動作させるにはどうすればよいSonataAdminBundleですか? READMEOhGoogleMapFormTypeBundleに基づいて構成しました。これは私の方法です:configureFormFields

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->with("Map")
            ->add('latlng', new GoogleMapType())
        ->end()
    ;
}

エラーが発生します:

Please define a type for field `latlng` in `GM\AppBundle\Admin\PlaceAdmin`
4

2 に答える 2

1

GoogleMapType最初に をサービスとして app/config.ymlファイルに定義しました。

services:
    # ...
    oh.GoogleMapFormType.form.type.googlemapformtype:
        class: Oh\GoogleMapFormTypeBundle\Form\Type\GoogleMapType
        tags:
            - { name: form.type, alias: oh_google_maps }

私は Symfony2 にちょっと慣れていないので、何らかの理由でエイリアスがoh_google_maps.

次に、Entity クラスに緯度と経度を格納するためのフィールドと関数を設定します。

private $latlng;

private $latitude;

private $longitude;

public function setLatlng($latlng)
{
    $this->latlng = $latlng;
    $this->latitude = $latlng['lat'];
    $this->longitude = $latlng['lng'];
    return $this;
}

/**
* @Assert\NotBlank()
* @OhAssert\LatLng()
*/
public function getLatLng()
{
    return array('lat' => $this->latitude,'lng' => $this->longitude);
}

最後に、カスタム Sonata Admin クラスのconfigureFormFields関数で:

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        //...
        ->add('latlng', 'oh_google_maps', array());
}
于 2013-12-01T20:38:21.093 に答える