Chciałbym wyświetlić zdefiniowany element w html. twig. Na początek zwykły wprowadzony z palca, docelowo pobierany z bazy. Próbuje odnieść się do materiałów jakie znalazłem w sieci ale coś jest nie tak. Może ktoś podpowie w czym rzecz.
Tak wygląda entity:
/**
* Products
*
* @ORM\Table()
* @ORM\Entity
*/
class Products
{
/**
* @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;
/**
* Set id
*
* @param integer $id
* @return Products
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Products
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
public function __toString()
{
return $this->getName();
}
}
Tak zdefiniowana Form:
class ProductsForm extends AbstractType
{
public function productsForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('save', 'submit');
}
public function getName()
{
return 'product';
}
}
a tak treść controllera:
/**
* @Route("/shop/", name="shop")
*/
public function shopAction()
{
// $em = $this -> getDoctrine() -> getManager();
// $product = $em -> getRepository('AppBundle:Products')->findOneBy(array('id' => '1'));
$product = new Products();
$product->setName('pierwszy');
$product->setId(1);
$form = $this->createForm(new ProductsForm(), $product);
return $this->render('default/shop.html.twig', array(
'form' => $form->createView()));
}
no i wywołanie w html.twig:
{% block body %}
{{ form.product.name }}
{% endblock %}
Jakbym nie odwołał się do elementu to nie znajduje ani product ani name. Robię to analogicznie do przykładów jakie znalazłem i jakie sam wcześniej robiłem ale coś jest nie tak. Proszę o pomoc.