[英]Attempted to load class from namespace Do you need to “use” it from another namespace?
I use doctrine 2. I created an entity Product and when I want to add a product in the database it return me an error: 我使用原则2。我创建了一个实体产品,当我想在数据库中添加产品时,它返回一个错误:
Attempted to load class "Produit" from namespace "Dwm\\catalogueBundle\\Entity" in /Applications/MAMP/htdocs/RESTApi/src/Dwm/catalogueBundle/Controller/DefaultController.php line 41. Do you need to "use" it from another namespace? 尝试从/Applications/MAMP/htdocs/RESTApi/src/Dwm/catalogueBundle/Controller/DefaultController.php第41行中的名称空间“ Dwm \\ catalogueBundle \\ Entity”中加载类“ Produit”。是否需要从另一个“使用”它命名空间?
<?php
namespace Dwm\catalogueBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Dwm\catalogueBundle\Entity\Produit;
class DefaultController extends Controller
{
/**
* @Route("/addProduit/{nom}/{prix}")
* @Template()
*/
public function addProduitAction($nom, $prix)
{
$p = new Produit();
$p->setNom($nom);
$p->setPrix($prix);
$em = $this->getDoctrine()->getManager();
$em->persist($p);
$em->flush();
return array('ptoduit'=>$p);
}
}
Don't think this is the root cause, but your bundle name should be in camel case: CatalogueBundle rather than catalogueBundle. 不要以为这是根本原因,但您的捆绑包名称应采用驼峰形式:CatalogueBundle而不是catalogueBundle。 It might not be causing this, but will definitely mess up other things as you go on.
这可能不是造成这种情况的原因,但是在您继续进行时,肯定会弄乱其他情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.