我在Symfony2中为新闻稿表格安装了电子邮件验证程序。本地一切正常,但如果我将整个文件夹上传到我的虚拟主机,我会收到以下错误消息:
Fatal error: Class 'Symfony\Component\Validator\Constraints\email' not found in /home/donacico/public_html/spendu/donaci14/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php on line 64
我的验证yml如下所示:
# src/Dbe/DonaciBundle/Resources/config/validation.yml
Dbe\DonaciBundle\Entity\Newsletter:
properties:
email:
- email:
message: The email "{{ value }}" is not a valid email.
checkMX: true
Dbe\DonaciBundle\Entity\Contact:
properties:
email:
- email:
message: The email "{{ value }}" is not a valid email.
checkMX: true
以下是创建控制器的操作:
/**
* Creates a new Newsletter entity.
*
*/
public function createAction(Request $request) {
$entity = new Newsletter();
$form = $this -> createCreateForm($entity);
$form -> handleRequest($request);
if ($form -> isValid()) {
$em = $this -> getDoctrine() -> getManager();
$em -> persist($entity);
$em -> flush();
$this -> get('session') -> getFlashBag() -> add('newsletterSubscribed', 'Thank you for subscribing!');
}
return $this -> render('DbeDonaciBundle:UnderConstruction:index.html.twig', array('entity' => $entity, 'form' => $form -> createView(), ));
}
同样在config.yml文件中,我启用了验证:
framework:
validation: { enable_annotations: true }
知道什么可能导致此错误吗?
答案 0 :(得分:3)
如果您在Linux系统上工作,则区分大小写。
'Symfony\Component\Validator\Constraints\email'
到
'Symfony\Component\Validator\Constraints\Email'
否则自动加载器无法找到文件和类。
答案 1 :(得分:0)
这确实是一个区分大小写的错误情况,但我纠正了错误的一个。
的src / DbeDonaciBundle /资源/配置/ validation.yml
Dbe\DonaciBundle\Entity\Newsletter:
properties:
email:
- Email :
message: The email "{{ value }}" is not a valid email.
checkMX: true