嘿,我的symfony2项目中有两个包。一个是Bundle,另一个是PatentBundle。
我的app / config / route.yml文件是
MunichInnovationGroupPatentBundle:
resource: "@MunichInnovationGroupPatentBundle/Controller/"
type: annotation
prefix: /
defaults: { _controller: "MunichInnovationGroupPatentBundle:Default:index" }
MunichInnovationGroupBundle:
resource: "@MunichInnovationGroupBundle/Controller/"
type: annotation
prefix: /v1
defaults: { _controller: "MunichInnovationGroupBundle:Patent:index" }
login_check:
pattern: /login_check
logout:
pattern: /logout
我的控制器里面有
<?php
namespace MunichInnovationGroup\PatentBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use JMS\SecurityExtraPatentBundle\Annotation\Secure;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Security\Core\SecurityContext;
use MunichInnovationGroup\PatentBundle\Entity\Log;
use MunichInnovationGroup\PatentBundle\Entity\UserPatent;
use MunichInnovationGroup\PatentBundle\Entity\PmPortfolios;
use MunichInnovationGroup\PatentBundle\Entity\UmUsers;
use MunichInnovationGroup\PatentBundle\Entity\PmPatentgroups;
use MunichInnovationGroup\PatentBundle\Form\PortfolioType;
use MunichInnovationGroup\PatentBundle\Util\SecurityHelper;
use Exception;
/**
* Portfolio controller.
* @Route("/portfolio")
*/
class PortfolioController extends Controller {
/**
* Index action.
*
* @Route("/", name="v2_pm_portfolio")
* @Template("MunichInnovationGroupPatentBundle:Portfolio:index.html.twig")
*/
public function indexAction(Request $request) {
$portfolios = $this->getDoctrine()
->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios')
->findBy(array('user' => '$user_id'));
// rest of the method
}
修改:
我的实体类
<?php
namespace MunichInnovationGroup\PatentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* MunichInnovationGroup\PatentBundle\Entity\PmPortfolios
*
* @ORM\Table(name="pm_portfolios")
* @ORM\Entity
*/
class PmPortfolios
{
/**
* @var string $id
*
* @ORM\Column(name="id", type="string", length=36, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="UUID")
*/
private $id;
/**
* @var string $portfolioName
*
* @ORM\Column(name="portfolio_name", type="string", length=255, nullable=false)
*/
private $portfolioName;
/**
* @var text $description
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @var string $permalink
*
* @ORM\Column(name="permalink", type="string", length=255, nullable=false)
*/
private $permalink;
/**
* @var string $sharingCode
*
* @ORM\Column(name="sharing_code", type="string", length=255, nullable=false)
*/
private $sharingCode;
/**
* @var boolean $shared
*
* @ORM\Column(name="shared", type="boolean", nullable=false)
*/
private $shared;
/**
* @var integer $sharedPortfolioCalls
*
* @ORM\Column(name="shared_portfolio_calls", type="integer", nullable=true)
*/
private $sharedPortfolioCalls;
/**
* @var boolean $isDefault
*
* @ORM\Column(name="is_default", type="boolean", nullable=false)
*/
private $isDefault;
/**
* @var UmUsers
*
* @ORM\ManyToOne(targetEntity="UmUsers")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $user;
/**
* Get id
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Set portfolioName
*
* @param string $portfolioName
*/
public function setPortfolioName($portfolioName)
{
$this->portfolioName = $portfolioName;
}
/**
* Get portfolioName
*
* @return string
*/
public function getPortfolioName()
{
return $this->portfolioName;
}
/**
* Set description
*
* @param text $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Get description
*
* @return text
*/
public function getDescription()
{
return $this->description;
}
/**
* Set permalink
*
* @param string $permalink
*/
public function setPermalink($permalink)
{
$this->permalink = $permalink;
}
/**
* Get permalink
*
* @return string
*/
public function getPermalink()
{
return $this->permalink;
}
/**
* Set sharingCode
*
* @param string $sharingCode
*/
public function setSharingCode($sharingCode)
{
$this->sharingCode = $sharingCode;
}
/**
* Get sharingCode
*
* @return string
*/
public function getSharingCode()
{
return $this->sharingCode;
}
/**
* Set shared
*
* @param boolean $shared
*/
public function setShared($shared)
{
$this->shared = $shared;
}
/**
* Get shared
*
* @return boolean
*/
public function getShared()
{
return $this->shared;
}
/**
* Set sharedPortfolioCalls
*
* @param integer $sharedPortfolioCalls
*/
public function setSharedPortfolioCalls($sharedPortfolioCalls)
{
$this->sharedPortfolioCalls = $sharedPortfolioCalls;
}
/**
* Get sharedPortfolioCalls
*
* @return integer
*/
public function getSharedPortfolioCalls()
{
return $this->sharedPortfolioCalls;
}
/**
* Set isDefault
*
* @param boolean $isDefault
*/
public function setIsDefault($isDefault)
{
$this->isDefault = $isDefault;
}
/**
* Get isDefault
*
* @return boolean
*/
public function getIsDefault()
{
return $this->isDefault;
}
/**
* Set user
*
* @param MunichInnovationGroup\PatentBundle\Entity\UmUsers $user
*/
public function setUser(\MunichInnovationGroup\PatentBundle\Entity\UmUsers $user)
{
$this->user = $user;
}
/**
* Get user
*
* @return MunichInnovationGroup\PatentBundle\Entity\UmUsers
*/
public function getUser()
{
return $this->user;
}
}
我的主要班级:MunichInnovationGroupPatentBundle.php
<?php
namespace MunichInnovationGroup\PatentBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class MunichInnovationGroupPatentBundle extends Bundle
{
}
当我尝试加载localhost / web / app_dev.php / portfolio
时它说
Unknown Entity namespace alias 'MunichInnovationGroupPatentBundle'.
我无法弄清楚这个错误 如果有人有任何想法,请帮我,我google了很多:(
提前致谢 500内部服务器错误 - ORMException
答案 0 :(得分:29)
请检查你的config.yml。
评论mappings
的{{1}}部分
你应该有entity_managers
那是:
MunichInnovationGroupPatentBundle: ~
答案 1 :(得分:8)
在我的情况下,我在提供商
下的security.yml中缺少名称空间名称我有:
entity: { class: AdministratorBundle:AdminUser }
并且需要:
entity: { class: NamespaceAdministratorBundle:AdminUser }
答案 2 :(得分:6)
如果您使用2个或更多实体经理 - 您还需要指定经理 的 getManager(&#39; YourManager&#39)强>
$repository =
$this->getDoctrine()
->getManager('YourManager')
->getRepository('YourBundle:YourEntity');
答案 3 :(得分:2)
检查捆绑逻辑名称(MunichInnovationGroupPatentBundle)。捆绑逻辑名称是捆绑包的主要类的名称,例如JobsBundle
并提供您的实体源代码。
答案 4 :(得分:1)
文档here声明您可以使用字符串 'MunichInnovationGroupPatentBundle:PmPortfolios'
作为 'MunichInnovationGroupPatentBundle\Entity\PmPortfolios'
的快捷方式,只要您的实体位于您的捆绑包的实体名称空间。
您的捆绑包是 MunichInnovationGroupBundle ,而不是
->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios')
使用
->getRepository('MunichInnovationGroupPatentBundle\Entity\PmPortfolios')
答案 5 :(得分:1)
通过添加一些字段,尝试在config.yml文件中更明确:
orm:
...
mappings:
MunichInnovationGroupPatentBundle:
type: annotation
dir: "MunichInnovationGroupPatentBundle/Controller"
is_bundle: true
prefix: MunichInnovationGroup\PatentBundle
alias: MunichInnovationGroupPatentBundle
[more mappings..]
答案 6 :(得分:1)
请检查你的config.yml + AppKernel.php
config.yml 必须
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
或将 auto_mapping 替换为
mappings:
StoreShopBundle: ~
了解更多信息,请查看:https://stackoverflow.com/a/37652091/5809937
AppKernel.php 中的不要忘记检查捆绑是否被激活:
new MunichInnovationGroup\PatentBundle\MunichInnovationGroupPatentBundle(),
答案 7 :(得分:0)
尝试使用没有核心文件夹名称的bandle名称时,我有这个。它在config / security.yml
中我的案例中的文件夹结构是下一个src / Dp / UserBundle /....
我改变了这一点 `提供商:
main:
entity: { class: UserBundle:User, property: username }`
对此
`提供商:
main:
entity: { class: DpUserBundle:User, property: username }`
所以复制未知实体名称的名称并搜索项目中的每个条目,检查 - 它们必须带有文件夹前缀(在我的情况下是Dp)
答案 8 :(得分:0)
在Symfony版本2.3.7中,我使用了NameofCompanySomethingBundle:EntityRequired,例如: AcmeBlogBundle:用户和它的工作原理。
自动映射:在config.yml中的orm:下使用了true(默认值)。
答案 9 :(得分:0)
如果使用多个实体管理器而未在控制器功能中指定实体管理器,则会发生此错误。
$em = $this->get('doctrine.orm.//your_entity_manager_name_here//_entity_manager');
$dql = "SELECT ...";
$query = $em->createQuery($dql);
这对我有用。
答案 10 :(得分:0)
打开您的app \ config.yml,必须为
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
replace to
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
MunichInnovationGroupPatentBundle: ~