更新:由于我没有得到任何答案,我使用一个更简单的例子重写了整篇文章.希望这有助于揭露问题.
我在表单验证方面遇到了麻烦.我可以使NotBlank()断言起作用,但Type()对我不起作用.首先,这是代码:
/* ...\Entity\LineItem.php */
<?php
namespace Rialto\ExperimentBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class LineItem
{
/**
* @var integer
* @Assert\NotBlank()
* @Assert\Type(type="integer")
*/
private $quantity = 0;
public function getQuantity()
{
return $this->quantity;
}
public function setQuantity($quantity)
{
$this->quantity = $quantity;
}
}
/* ...\Controller\DefaultController.php */
<?php
namespace Rialto\ExperimentBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Rialto\ExperimentBundle\Entity\LineItem;
class DefaultController extends Controller
{
public function indexAction()
{
return $this->testValidation();
}
private function testValidation()
{
$item = new LineItem();
$form = $this->createFormBuilder($item) …Run Code Online (Sandbox Code Playgroud)