This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Users</h1> | |
{% if users|length == 0 %} | |
{# No users to display... #} | |
<p>Could not find any users :(</p> | |
{% else %} | |
<table> | |
<thead> | |
<td>Username</td> | |
<td>Email address</td> | |
<td>Password</td> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyCompany\BlogBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/* Include the required validators */ | |
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; | |
use Symfony\Component\Validator\Constraints as Assert; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyCompany\BlogBundle\Form; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilder; | |
class UserType extends AbstractType | |
{ | |
public function buildForm(FormBuilder $builder, array $options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyCompany\BlogBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
use Doctrine\ORM\EntityRepository; | |
/* Import the entity and form classes */ | |
use MyCompany\BlogBundle\Entity\User; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use MyCompany\BlogBundle\Entity\Article; | |
use MyCompany\BlogBundle\Form\ArticleType; | |
use Symfony\Component\HttpFoundation\Request; | |
/* ... rest of the controller */ | |
public function updateAction(Request $request) | |
{ | |
$article = new Article(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* ... rest of the controller */ | |
$article = new Article(); | |
/* do stuff to the Article entity instance */ | |
$validator = $this->get('validator'); | |
$errors = $validator->validate($author); | |
/* rest of the controller... */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// src/MyCompany/BlogBundle/Entity/Article.php | |
use Symfony\Component\Validator\Constraints as Assert; | |
class Article | |
{ | |
/** | |
* @Assert\NotBlank() | |
*/ | |
public $title; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use MyCompany\BlogBundle\Form\Type\ArticleType; | |
use MyCompany\BlogBundle\Entity\Article; | |
/* ... rest of the controller */ | |
/** | |
* @Route("/article/add", name="post_add") | |
* @Template() | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// src/MyCompany/BlogBundle/Form/Type/ArticleType.php | |
namespace MyCompany\BlogBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilder; | |
class ArticleType extends AbstractType | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* ... rest of the controller */ | |
if ($this->getRequest()->getMethod() == 'POST') { | |
/* First we 'bind' the postback data to the form */ | |
$form->bind($this->getRequest()->get('form')); | |
if ($form->isValid()) { | |
/* Now we get the data as an associative array */ | |
$formdata = $form->getData(); | |