您好我不知道如何修复此错误,我在谷歌搜索但我没有解决此错误,我只是想按照本教程http://tutorial.symblog.co.uk/docs/validators-and-forms.html,任何帮助将不胜感激
ClassNotFoundException: Attempted to load class "Enquiry" from namespace
"Blogger\BlogBundle\Entity" in
C:\wamp\www\symblog.dev\src\Blogger\BlogBundle\Controller\PageController.php line 22.
Do you need to "use" it from another namespace?
这是文件代码:
<?php
// src/Blogger/BlogBundle/Controller/PageController.php
namespace Blogger\BlogBundle\Controller;
// Import new namespaces
use Blogger\BlogBundle\Entity\Enquiry;
use Blogger\BlogBundle\Form\EnquiryType;
class PageController extends Controller
{
public function indexAction()
{
return $this->render('BloggerBlogBundle:Page:index.html.twig');
}
public function aboutAction()
{
return $this->render('BloggerBlogBundle:Page:about.html.twig');
}
public function contactAction()
{
$enquiry = new Enquiry();
$form = $this->createForm(new EnquiryType(), $enquiry);
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
// Perform some action, such as sending an email
// Redirect - This is important to prevent users re-posting
// the form if they refresh the page
return $this->redirect($this->generateUrl('BloggerBlogBundle_contact'));
}
}
return $this->render('BloggerBlogBundle:Page:contact.html.twig', array('form' => $form->createView()
));
}
}
答案 0 :(得分:0)
确保:
1 您的文件名称为Enquiry.php
2 它位于文件夹Blogger/BlogBundle/Entity
3 称为class Enquiry
4 命名空间为namespace Blogger\BlogBundle\Entity;
注意:原因是这通常是由于文件名,类名,用语句或命名空间中的拼写错误。
答案 1 :(得分:0)
我解决了它,就像这样开始PageController.php:
<?php
// src/Blogger/BlogBundle/Controller/PageController.php
namespace Blogger\BlogBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Blogger\BlogBundle\Entity\Enquiry;
use Blogger\BlogBundle\Form\EnquiryType;
如果您找到更好的解决方案,请告诉我
答案 2 :(得分:0)
如果您确定您的命名空间是正确的,请检查您的PHP文件是否真的有.php
扩展名。