0
嘗試獲取視圖中實體中定義的斷言值。訪問Symfony在樹枝視圖中聲明
使用: Symfony的2.8 奏管理員:3.1
我在模型中這樣定義的斷言:
/**
* @var string
* @Assert\Length(
* min = 8,
* max = 60,
* minMessage = "Longer than {{ limit }}",
* maxMessage = "Shorter than {{ limit }}"
*)
* @ORM\Column(name="title", type="string", length=60)
*/
private $title;
管理形式使用定製formtype加載定製視圖:
<?php
namespace CustomBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TextCountType extends AbstractType
{
public function getParent()
{
return TextType::class;
}
}
而且視圖:
{% block text_count_widget %}
{% spaceless %}
{{ block('form_widget_simple') }}
<script>
// some custom live validation
// HERE i need access to the Asserts
</script>
{% endspaceless %}
{% endblock %}
我的問題是: 有沒有辦法訪問樹枝代碼中的斷言? 我不想在每個實體的管理員類中重新定義它。
謝謝你的幫助。