简体   繁体   English

尝试从名称空间加载类是否需要从另一个名称空间“使用”它?

[英]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.

相关问题 试图从命名空间加载类。 您是否忘记了另一个命名空间的“use”语句? 使用供应商 php 命名空间 - Attempted to load class from namespace. Did you forget a "use" statement for another namespace? with vendor php namespace 尝试从命名空间加载类是否忘记了另一个命名空间的“use”语句? - Attempted to load class from namespace did you forget a “use” statement for another namespace? 尝试从命名空间“Symfony\\WebpackEncoreBundle”加载类“WebpackEncoreBundle”。 您是否忘记了另一个命名空间的“use”语句? - Attempted to load class "WebpackEncoreBundle" from namespace "Symfony\WebpackEncoreBundle". Did you forget a "use" statement for another namespace? 尝试从命名空间“knp \\ Bundle \\ PaginatorBundle”加载类“knpPaginatorBundle”。你忘记了另一个命名空间的“use”语句吗? - Attempted to load class “knpPaginatorBundle” from namespace “knp\Bundle\PaginatorBundle”.Did you forget a “use” statement for another namespace? 试图从命名空间“App\DataFixtures”加载 class“BaseFixture”。 您是否忘记了另一个名称空间的“使用”语句? - Attempted to load class "BaseFixture" from namespace "App\DataFixtures". Did you forget a "use" statement for another namespace? 尝试从命名空间“DoctrineExtensions \ Query \ Mysql”加载类“Month”。您是否忘记了另一个命名空间的“use”语句 - Attempted to load class “Month” from namespace “DoctrineExtensions\Query\Mysql”. Did you forget a “use” statement for another namespace 尝试从全局命名空间加载类“Memcached”。 您是否忘记了“使用”语句? - Attempted to load class “Memcached” from the global namespace. Did you forget a “use” statement? 尝试从全局命名空间加载 class “DOMDocument”。 您是否忘记了“使用”声明? - Attempted to load class "DOMDocument" from the global namespace. Did you forget a "use" statement? 试图从全局名称空间中加载类“ Thread”。 您是否忘记了“使用”声明? - Attempted to load class “Thread” from the global namespace. Did you forget a “use” statement? Symfony2尝试从全局名称空间加载类。 您是否忘记了“使用”声明? - Symfony2 Attempted to load class from the global namespace. Did you forget a “use” statement?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM