Wie füge ich Validierungsbeschränkungen hinzu "Feld ist erforderlich" in Symfony2 PostType-Klasse? Irgendwelche Vorschläge? Ich bin neu in SF2 und ich bearbeite nur, was von früheren Entwicklern gemacht wurde.Feld mit Abfrage sollte nicht leer sein
use Symfony\Component\Validator\Constraints\NotBlank;
class BlogPostType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$blogPostCategories = BlogPostCategoryQuery::create()
->filterByBlogPost($builder->getData())
->find();
$categoryIds = array();
foreach ($blogPostCategories as $blogPostCategory) {
$categoryIds[] = $blogPostCategory->getCategory()->getId();
}
$queryOptions = array(
'option_status' => Categorypeer::STATUS_ACTIVE,
'option_category_ids' => $categoryIds
);
$categories = CategoryQuery::create()
->filterActiveCategoriesByOptions($queryOptions)
->find();
$builder->add('category_ids', 'model', array(
'label' => 'Category',
'mapped' => false,
'class' => 'Deal\MainBundle\Model\Category',
'query' => CategoryQuery::create()
->filterActiveCategoriesByOptions()
->orderByName(),
'property' => 'name',
'empty_value' => 'Select categories',
'empty_data' => null,
'required' => true,
'multiple' => true,
'data' => $categories,
'constraints' => array(
new NotBlank(array(
'message' => 'Your message can not be blank! Ouch!'
)),
)
));
Danke
ich meinen Code aktualisieren und es tut – phpmeter
@jlacsonph arbeiten Können Sie nach, wie Sie das umgesetzt, was ich oben geschrieben habe? – martin
Hallo, überprüfe meinen aktualisierten Code nochmal, danke – phpmeter