
Data Validation
Constraints, custom validators, validation groups, Entity validation, DTO validation
1What is the main role of the Symfony Validator component?
What is the main role of the Symfony Validator component?
Câu trả lời
The Symfony Validator component validates data according to defined rules called constraints. It can validate objects, scalar values and arrays, returning a list of violations if rules are not met. This component is integrated with forms but can also be used independently.
2Which constraint should be used to verify that a field is not empty or null?
Which constraint should be used to verify that a field is not empty or null?
Câu trả lời
The NotBlank constraint checks that a value is not empty (empty string, null, or empty array). It differs from NotNull which accepts an empty string. NotBlank is most commonly used for required form fields as it also rejects strings containing only whitespace.
3How to apply a validation constraint on an entity property using PHP 8 attributes?
How to apply a validation constraint on an entity property using PHP 8 attributes?
Câu trả lời
Since PHP 8, validation constraints are applied via attributes directly above properties. The syntax uses the Assert prefix with the Symfony\Component\Validator\Constraints namespace. This approach is more concise than DocBlock annotations and benefits from native PHP support.
Which constraint validates that a string matches a valid email format?
How to validate the length of a string with minimum and maximum values?
+15 câu hỏi phỏng vấn
Các chủ đề phỏng vấn Symfony khác
Modern PHP (8.1+)
Symfony Basics
Routing & Controllers
Twig & Templates
Doctrine ORM Basics
Symfony Forms
Dependency Injection & Services
Security & Authentication
Doctrine Advanced
API Platform
Serializer Component
Events & Event Subscribers
Console & Commands
Messenger Component
HTTP Client
Cache & Performance
Workflow Component
Testing Symfony
Mailer Component
Translations & i18n
EasyAdmin Bundle
Symfony Architecture
Performance & Optimization
Security Advanced
Custom Bundles
Microservices with Symfony
Real-time & WebSockets
Deployment & DevOps
Nắm vững Symfony cho lần phỏng vấn tiếp theo
Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.
Bắt đầu miễn phí