I’m new in symfony2 and i’m tryting to create a autoComplete form with all airports.I installed GenemuFormBundle and i created a database, but i don’t really understand how to make it works.This is what i did already:
Any idea how to do it ? Thank you
PostType.php
<?php
namespace FLY\BookingsBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class PostType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('departure', 'genemu_jqueryautocomplete_entity', array(
'class' => 'FLYBookingsBundle\Entity\Post',
'property' => 'departure',
))
->add('arrival', 'genemu_jqueryautocomplete_entity', array(
'class' => 'FLYBookingsBundle\Entity\Post',
'property' => 'arrival',
))
->add('departuredate')
->add('arrivaldate')
->add('compagny','text')
->add('price')
;
}
Post.php
<?php
namespace FLY\BookingsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Post
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="FLY\BookingsBundle\Entity\PostRepository")
*/
class Post
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var array
*
* @ORM\Column(name="departure", type="array")
*/
private $departure;
/**
* @var array
*
* @ORM\Column(name="arrival", type="array")
*/
private $arrival;
/**
* @var \DateTime
*
* @ORM\Column(name="departuredate", type="datetime")
*/
private $departuredate;
/**
* @var \DateTime
*
* @ORM\Column(name="arrivaldate", type="datetime")
*/
private $arrivaldate;
/**
* @var float
*
* @ORM\Column(name="pounds", type="float")
*/
private $pounds;
/**
* @var float
*
* @ORM\Column(name="price", type="float")
*/
private $price;
/**
* @var array
*
* @ORM\Column(name="compagny", type="array")
*/
private $compagny;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set departure
*
* @param array $departure
* @return Post
*/
public function setDeparture($departure)
{
$this->departure = $departure;
return $this;
}
/**
* Get departure
*
* @return array
*/
public function getDeparture()
{
return $this->departure;
}
/**
* Set arrival
*
* @param array $arrival
* @return Post
*/
public function setArrival($arrival)
{
$this->arrival = $arrival;
return $this;
}
/**
* Get arrival
*
* @return array
*/
public function getArrival()
{
return $this->arrival;
}
/**
* Set departuredate
*
* @param \DateTime $departuredate
* @return Post
*/
public function setDeparturedate($departuredate)
{
$this->departuredate = $departuredate;
return $this;
}
/**
* Get departuredate
*
* @return \DateTime
*/
public function getDeparturedate()
{
return $this->departuredate;
}
/**
* Set arrivaldate
*
* @param \DateTime $arrivaldate
* @return Post
*/
public function setArrivaldate($arrivaldate)
{
$this->arrivaldate = $arrivaldate;
return $this;
}
/**
* Get arrivaldate
*
* @return \DateTime
*/
public function getArrivaldate()
{
return $this->arrivaldate;
}
/**
* Set pounds
*
* @param float $pounds
* @return Post
*/
public function setPounds($pounds)
{
$this->pounds = $pounds;
return $this;
}
/**
* Get pounds
*
* @return float
*/
public function getPounds()
{
return $this->pounds;
}
/**
* Set price
*
* @param float $price
* @return Post
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return float
*/
public function getPrice()
{
return $this->price;
}
/**
* Set compagny
*
* @param array $compagny
* @return Post
*/
public function setCompagny($compagny)
{
$this->compagny = $compagny;
return $this;
}
/**
* Get compagny
*
* @return array
*/
public function getCompagny()
{
return $this->compagny;
}
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'FLY\BookingsBundle\Entity\Post'
));
}
/**
* @return string
*/
public function getName()
{
return 'fly_bookingsbundle_post';
}
}
index.html.twig
{% extends "::base.html.twig" %}
{% block header %}
{% endblock header %}
{% block content %}
<h1>Post list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>Departure</th>
<th>Arrival</th>
<th>Departuredate</th>
<th>Arrivaldate</th>
<th>Pounds</th>
<th>Price</th>
<th>Compagny</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('post_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.departure }}</td>
<td>{{ entity.arrival }}</td>
<td>{% if entity.departuredate %}{{ entity.departuredate|date('Y-m-d H:i:s') }}{% endif %}</td>
<td>{% if entity.arrivaldate %}{{ entity.arrivaldate|date('Y-m-d H:i:s') }}{% endif %}</td>
<td>{{ entity.pounds }}</td>
<td>{{ entity.price }}</td>
<td>{{ entity.compagny }}</td>
<td>
<ul>
<li>
<a href="{{ path('post_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('post_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('post_new') }}">
Create a new entry
</a>
</li>
</ul>
{% endblock content %}
{% block foot_script %}
{% endblock foot_script %}
{% block footer %} {% endblock footer %}