Buenas,
Hace un par de dias se hizo el último gran update de los forms, el cual trae Annotations
, un pequeño ejemplo por si quieren meter mano:
Entity
Código PHP:
Ver originalnamespace Application\Entity;
use Doctrine\ORM\Mapping as ORM,
Zend\Form\Annotation as Form,
Zend\Stdlib\ArraySerializableInterface,
Application\Model\PostInterface,
DateTime;
/**
* @ORM\Entity()
* @ORM\HasLifecycleCallbacks
*/
class Post implements PostInterface, ArraySerializableInterface
{
const NOT_DRAFT = 0;
const DRAFT = 1;
const NOT_TRASH = 0;
const TRASH = 1;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @Form\Attributes({"type":"hidden"})
* @Form\AllowEmpty
*/
protected $id;
/**
* @ORM\Column()
* @Form\Required
* @Form\Filter({"name":"StripTags"})
* @Form\Filter({"name":"StringTrim"})
* @Form\Filter({"name":"StringToUpper"})
* @Form\Validator({"name":"Alnum"})
*/
protected $title;
/**
* @ORM\Column()
* @Form\Attributes({"type":"textarea"})
* @Form\Filter({"name":"StripTags"})
* @Form\Filter({"name":"StringTrim"})
*/
protected $content;
/**
* @ORM\Column(name="created_at", type="datetime")
* @Form\AllowEmpty
* @Form\Validator({"name":"Date"})
*/
protected $createdAt;
/**
* @ORM\Column(name="updated_at", type="datetime")
* @Form\AllowEmpty
* @Form\Validator({"name":"Date"})
*/
protected $updatedAt;
/**
* @ORM\Column(type="boolean")
*/
protected $draft;
/**
* @ORM\Column(type="boolean")
*/
protected $trash;
}
Controller
Código PHP:
Ver originalpublic function indexAction()
{
$request = $this->getRequest();
$builder = new AnnotationBuilder();
$entity = new Post();
$form = $builder->createForm($entity);
'name' => 'submit',
'type' => 'submit'
)
));
$form->bind($entity);
if($request->isPost()){
$form->setData($request->post());
if($form->isValid()) {
$em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
$em->persist($form->getData());
$this->flashMessenger()->addMessage('Entity persisted.');
$this->redirect()->toRoute('home');
}
}
return new ViewModel
(array('form' => $form)); }
sencillamente fantástico :alabanza:, tengan en cuenta que es la primera aproximación.
Saludos.