除了我之前的问题将zend 过滤器和验证链附加到模型/学说实体中,我尝试了 Spiffy 框架,但我得到了堆栈,但异常如下: Exception No form element was specified for "title" and one not be从“Spiffy\Zend\Form”自动确定。在我的实体中,我有这个:
<?php
namespace Entities;
use Doctrine\ORM\Mapping as ORM;
use Spiffy\Doctrine\AbstractEntity as Entity;
use Spiffy\Doctrine\Annotations\Filters as Filter;
use Spiffy\Doctrine\Annotations\Validators as Assert;
/** @ORM\Entity(repositoryClass="Repositories\PostRepository") */
class Post extends Entity {
public function __construct()
{
$this->created = new \DateTime("now");
$this->comments = new \Doctrine\Common\Collections\ArrayCollection();
}
public function __get($property)
{
return $this->$property;
}
public function __set($name, $value)
{
$this->$name = $value;
return $this->$name;
}
/**
* @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue
*/
private $id;
/**
* @var string $title
* @Filter\Alnum
* @Assert\StringLength(5)
* @ORM\Column(type="string",length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $body;
/**
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @ORM\OneToMany(targetEntity="Comment", mappedBy="post", fetch="LAZY")
*/
private $comments;
}
我的表格是这样的:
<?php
use \Spiffy\Zend\Form as Form;
class Application_Form_Post extends Form
{
public function init()
{
//var_dump($this->getEntity()); //returns null
// die;
$this->add('title');
$this->add('body');
$this->addElement('submit', 'submit', array(
));
}
}
所以我在这里阻止自己。谢谢您的帮助。