Bonjour a tout le monde !
je suis dans le besoin de collocter la longitude et la latitude en me servant de google maps (http://xilinus.com/jquery-addresspic...mos/index.html) depuis un formulaire symfony2 et je n'ai pas pu le faire et je suis tombe sur ce bundle qui répond parfaitement a mon besoin: https://github.com/ollietb/OhGoogleMapFormTypeBundle seulement après l'avoir installer et suivre scrupuleusement les quelques lignes de configuration requise, je n'arrive toujours pas a le faire fonctionner. Au faite, il génère toujours cette erreur: Variable "id" does not exist in OhGoogleMapFormTypeBundle:Form:google_maps.html.twig at line 4
Mon objectif est vraiment de faire fonctionner le bundle a tout prix et je n'ai pas l'intention de faire son update après (si ce n'ai d'y contribuer d'abord officiellment) si bien que même s'il faut modifier ses fichiers d'origine qui se trouvent dans le répertoire vendor, je le fairai (quoi que je suis extrêmement gêné de faire cela) alors je prie quiconque peut vraiment m'aider a le faire fonctionner car cela fait déjà plus de d'une semaine que je galère. Ou s'il existe un autre bundle qui fait la même chose (http://xilinus.com/jquery-addresspic...mos/index.html) surtout (et seulement ) collecter la longitude et la latitude en faisant glisser le marqueur sur la carte, alors je suis GRAND PRENEUR
voici le code du formulaire qui genere l'erreur (depuis le vendor):et voici ma vue qui doit afficher le formulaire:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 {% block oh_google_maps_widget %} <div {{ block('widget_container_attributes') }}> {% block oh_google_maps_html %} <div id="{{ id }}_container"> <input type="text" id="{{ id }}_input" /><button id="{{ id }}_search_button" class="btn">Search</button><br /><a href="#" id="{{ id }}_current_position">Current location</a> <div id="{{ id }}_map_canvas" class="gmap" style="width: {{ map_width }}px; height: {{ map_height }}px"></div> <div id="{{ id }}_error"></div> </div> {% endblock %} {% block oh_google_maps_fields %} {% for child in form %} {{ form_row(child) }} {% endfor %} {% endblock %} {% block oh_google_maps_javascripts %} {% if include_jquery %} <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> {% endif %} {% if include_gmaps_js %} <script type="text/javascript" src="//maps.google.com/maps/api/js?sensor=true"></script> {% endif %} {% javascripts '@OhGoogleMapFormTypeBundle/Resources/public/js/jquery.ohgooglemaps.js' %} <script type="text/javascript" src="{{ asset_url }}"></script> {% endjavascripts %} {% endblock %} {% block oh_google_maps_javascript %} {% block oh_google_maps_callback %} <script type="text/javascript"> var oh_google_maps_callback = function(location, gmap){ // your callback function here } </script> {% endblock %} <script type="text/javascript"> $(function(){ $('#{{ id }}_map_canvas').ohGoogleMapType({ 'search_input_el' : $('#{{ id }}_input'), 'search_action_el' : $('#{{ id }}_search_button'), 'search_error_el' : $('#{{ id }}_error'), 'current_position_el': $('#{{ id }}_current_position'), 'default_lat' : '{% if value is defined and value and attribute(value, lat_name) %}{{ attribute(value, lat_name) }}{% else %}{{ default_lat }}{% endif %}', 'default_lng' : '{% if value is defined and value and attribute(value, lng_name) %}{{ attribute(value, lng_name) }}{% else %}{{ default_lng }}{% endif %}', 'default_zoom' : {% if value is defined and value and value.lat and value.lng %}15{% else %}5{% endif %}, 'lat_field' : $('#{{ attribute(form, lat_name).vars.id }}'), 'lng_field' : $('#{{ attribute(form, lng_name).vars.id }}'), 'callback' : oh_google_maps_callback }); }); </script> {% endblock %} </div> {% endblock %}
voici mon formulaire symfony2:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 {% extends "OhGoogleMapFormTypeBundle:Form:fields.html.twig" %} {% block oh_google_maps_callback %} {{form(form)}} {% endblock %}
Et enfin voici mon objet sur lequel le formulaire est construit:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 <?php namespace Mpk\CmsBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Oh\GoogleMapFormTypeBundle\Form\Type\GoogleMapType; class CompanyType extends AbstractType { /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('Latlng', 'oh_google_maps') ; } /** * @param OptionsResolverInterface $resolver */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'Mpk\CmsBundle\Entity\Company' )); } /** * @return string */ public function getName() { return 'mpk_cmsbundle_company'; } }
Et voici mon fichier composer.json:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 <?php namespace Mpk\CmsBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Oh\GoogleMapFormTypeBundle\Validator\Constraints as OhAssert; /** * Company * * @ORM\Table() * @ORM\Entity(repositoryClass="Mpk\CmsBundle\Entity\CompanyRepository") */ class Company { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="name", type="string", length=255) */ private $name; /** * @var string * * @ORM\Column(name="lat", type="string", length=255) */ private $lat; /** * @var string * * @ORM\Column(name="lng", type="string", length=255) */ private $lng; public function setLatLng($latlng) { $this->setLat($latlng['lat']); $this->setLng($latlng['lng']); return $this; } /** * @Assert\NotBlank() * @OhAssert\LatLng() */ public function getLatLng() { return array('lat'=>$this->getLat(),'lng'=>$this->getLng()); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set name * * @param string $name * * @return Company */ public function setName($name) { $this->name = $name; return $this; } /** * Get name * * @return string */ public function getName() { return $this->name; } /** * Set lat * * @param string $lat * * @return Company */ public function setLat($lat) { $this->lat = $lat; return $this; } /** * Get lat * * @return string */ public function getLat() { return $this->lat; } /** * Set lng * * @param string $lng * * @return Company */ public function setLng($lng) { $this->lng = $lng; return $this; } /** * Get lng * * @return string */ public function getLng() { return $this->lng; } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 { "name": "MAPOUKA/my_project", "license": "proprietary", "type": "project", "autoload": { "psr-4": { "": "src/", "SymfonyStandard\\": "app/SymfonyStandard/" } }, "require": { "php": ">=5.3.9", "symfony/symfony": "2.7.*", "doctrine/orm": "^2.4.8", "doctrine/doctrine-bundle": "~1.4", "symfony/assetic-bundle": "~2.3", "symfony/swiftmailer-bundle": "~2.3", "symfony/monolog-bundle": "~2.4", "sensio/distribution-bundle": "~4.0", "sensio/framework-extra-bundle": "^3.0.2", "incenteev/composer-parameter-handler": "~2.0", "oh/google-map-form-type-bundle": "dev-master" }, "require-dev": { "sensio/generator-bundle": "~2.3" }, "scripts": { "post-root-package-install": [ "SymfonyStandard\\Composer::hookRootPackageInstall" ], "post-install-cmd": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" ], "post-update-cmd": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" ] }, "config": { "bin-dir": "bin" }, "extra": { "symfony-app-dir": "app", "symfony-web-dir": "web", "symfony-assets-install": "relative", "incenteev-parameters": { "file": "app/config/parameters.yml" } } }
Partager