问题
In addtion to my previous question Attache zend filters and validation chains to models/doctrine entities I have given a try to Spiffy framework, but I got stack with this exception like this: Exception No form element was specified for "title" and one not be determined automatically from "Spiffy\Zend\Form". In my entity I have this:
<?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;
}
And my form is like this:
<?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(
));
}
}
So I am block myself here. Thank you for your help.
回答1:
In my application.ini, I comented out this lines:
pluginPaths.Bisna\Application\Resource\ = "Bisna/Application/Resource"
and
autoloaderNamespaces[] = Bisna
but I still got the exception:
Uncaught exception 'ReflectionException' with message 'Class Doctrine\ORM\Mapping\Driver\AnnotationDriver does not exist' in C:\Spiffy\lib\Spiffy\Doctrine\Container.php on line 359
What is not clear for me, is that in the bisna resource I had something like this:
\Zend_Registry::set('doctrine', $container);
and in the spiffy resource I had like this:
`Zend_Registry::set('Spiffy_Doctrine', $container);`
But in my Boostrap.php, I had this two:
$this->bootstrap('doctrine');
$container = $this->getResource('doctrine');
I was expected to be a diffrence between doctrine and Spiffy_Doctrine, but is not. And something else that is for me, not understandable. I modify some line in Spiffy container like this:
try{
$reflClass = new ReflectionClass($driverClass);
}catch (LogicException $Exception) {
die('Not gonna make it in here...');
}
catch(ReflectionException $Exception)
{
die('Your class does not exist! ' );
}
but instead of cacthing the exception, I got this:
`Uncaught exception 'ReflectionException'`
Ps: Sorry for the duplication of content from the doctrine group from linekdin, but these are my answers. Rigth now I debug my application, maybe I will figure out what I'm missing, but any help will be great. Thank you.
来源:https://stackoverflow.com/questions/10462700/exception-no-form-element-was-specified-for-title-and-one-not-be-determined-au