【发布时间】:2014-04-22 15:12:12
【问题描述】:
我在使用 symfony 2 时遇到了问题。在某个点之前一切正常。
我有一个简单的控制器动作、一个实体类和一个表单(抽象类型)类。我遇到了问题:
ClassNotFoundException:尝试从 /var/www/dellf2/src/Blogger/BlogBundle/Controller/PageController.php 第 26 行中的命名空间“Symfony\Blogger\BlogBundle\Entity”加载类“查询”。你需要“从另一个命名空间使用”它?
我检查了 Enquiry.php,它位于正确的位置 (Blogger/BlogBundle/Entity/Enquiry.php)。我检查了权限,它看起来很好(755)。即使我尝试使用 include_once() 包含文件,它也不起作用。
查询.php
// src/Blogger/BlogBundle/Entity/Enquiry.php
namespace Blogger\BlogBundle\Entity;
class Enquiry
{
protected $name;
protected $email;
protected $subject;
protected $body;
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
public function getSubject()
{
return $this->subject;
}
public function setSubject($subject)
{
$this->subject = $subject;
}
public function getBody()
{
return $this->body;
}
public function setBody($body)
{
$this->body = $body;
}
}
?>
PageController.php
<?php
// src/Blogger/BlogBundle/Controller/PageController.php
namespace Blogger\BlogBundle\Controller;
//include_once('../Entity/Enquiry.php');
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Blogger\BlogBundle\Entity\Enquiry;
use Symfony\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()));
}
}
【问题讨论】: