17

Hey I have two bundles in my symfony2 project. one is Bundle and the other one is PatentBundle.

My app/config/route.yml file is

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

inside my controller i have

<?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
  }

Edit:

My Entity Class

<?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;
}

}

My bundle main class: MunichInnovationGroupPatentBundle.php

 <?php

  namespace MunichInnovationGroup\PatentBundle;

  use Symfony\Component\HttpKernel\Bundle\Bundle;

  class MunichInnovationGroupPatentBundle extends Bundle
 {
 }

when i try to load localhost/web/app_dev.php/portfolio

It says

   Unknown Entity namespace alias 'MunichInnovationGroupPatentBundle'.

I am unable to figure out this error please help me if anyone has any idea I googled it a lot :(

Thanks in advance 500 Internal Server Error - ORMException

Zoha Ali Khan
  • 1,659
  • 11
  • 37
  • 56
  • Try to check your PmPortfolios entity, if the namespace is correct. – Teo.sk Jun 17 '12 at 08:14
  • Another possible solution: http://stackoverflow.com/questions/12145101/how-to-address-the-bundle-in-php-app-console-generatedoctrinecrud – CodeSlave Jul 18 '15 at 12:11

11 Answers11

32

Please, check your config.yml.

Reviewed in section mappings of entity_managers.
You should have something like MunichInnovationGroupPatentBundle: ~

That is:

doctrine:
    orm:
        entity_managers:
            defaults:
                mappings:
                    MunichInnovationGroupPatentBundle: ~
Florent
  • 12,310
  • 10
  • 49
  • 58
Gsanlab
  • 321
  • 3
  • 5
  • 2
    Shouldn't it be enough with **auto_mapping: true**? – Jens Nov 23 '12 at 06:07
  • 2
    I just had this problem removing the default auto_mapping = true in my SF 2.3 app's config in order to add the stof/doctrineextensionsbundle mapping after SF2 threw an exception that auto_mapping wasn't a valid child. Re-adding auto_mapping as a sibling of the 'mappings' node (child of 'defaults' instead of a direct child of 'orm') above fixes the issues. – nealio82 Aug 02 '13 at 12:26
  • this answer is solved my problem. SF, see namespaces through that controller and start build entities properly. full description in that answer: http://stackoverflow.com/a/37652091/5809937 – Vladimir Ch Dec 14 '16 at 06:04
8

In my case I was missing namespace name in the security.yml under providers

I had:

entity: { class: AdministratorBundle:AdminUser }

and needed to have:

entity: { class: NamespaceAdministratorBundle:AdminUser }

Radek
  • 263
  • 3
  • 10
  • 1
    I forgot that the root class of the bundle includes the namespace at the beginning of its name. Thanks! Example for others: The root class for `Company\MyBundle` is `CompanyMyBundle`, not `MyBundle`. – jxmallett May 24 '15 at 23:15
7

If you use 2 or more entity managers -- you need to specify manager also getManager('YourManager')

$repository = 
    $this->getDoctrine()
    ->getManager('YourManager')
    ->getRepository('YourBundle:YourEntity');
mochalygin
  • 739
  • 6
  • 14
2

Check you bundle logical name (MunichInnovationGroupPatentBundle). Bundle logical name is name of main class of your bundle, e.g. JobsBundle

and provide your entity sourcecode.

Codium
  • 3,200
  • 6
  • 34
  • 60
  • when I changed my query to $em = $this->getDoctrine()->getEntityManager('pp_userdat'); em->->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios') ->findBy(array('user' => '$user_id')); then it gives me some Proxy error in ORM – Zoha Ali Khan Jun 17 '12 at 12:49
  • Fatal error: Doctrine\ORM\Proxy\ProxyFactory::getProxy() [function.require]: Failed opening required 'C:/wamp/www/idp/app/cache/dev/doctrine/orm/Proxies\MunichInnovationGroupPatentBundleEntityUmUsersProxy.php' (include_path='.;C:\php\pear') in C:\wamp\www\idp\vendor\doctrine\lib\Doctrine\ORM\Proxy\ProxyFactory.php on line 85 – Zoha Ali Khan Jun 17 '12 at 12:55
  • check app/cache folder permissions, maybe it can help – Codium Jun 17 '12 at 13:30
  • and I suggest you to create another question with this error if you won't solve it quickly – Codium Jun 17 '12 at 13:31
1

Documentation here states you can use the string 'MunichInnovationGroupPatentBundle:PmPortfolios' as shortcut to 'MunichInnovationGroupPatentBundle\Entity\PmPortfolios' as long as your entity lives under the Entity namespace of your bundle.

Your bundle is MunichInnovationGroupBundle so instead of

->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios')

use

->getRepository('MunichInnovationGroupPatentBundle\Entity\PmPortfolios')
Dharmesh Porwal
  • 1,406
  • 2
  • 12
  • 21
BartBiczBoży
  • 2,512
  • 2
  • 24
  • 33
1

Try being more explicit in your config.yml file by adding some fields:

orm:
    ...

    mappings:
        MunichInnovationGroupPatentBundle:
                type: annotation
                dir: "MunichInnovationGroupPatentBundle/Controller"
                is_bundle: true
                prefix: MunichInnovationGroup\PatentBundle
                alias: MunichInnovationGroupPatentBundle
        [more mappings..]
  • I was just about to add a response like this one, it worked for me with this approach, but not until I changed `alias:` to anything different from `MunichInnovationGroupPatentBundle` say: `alias: MunichInnovation` – juanmf Mar 25 '16 at 02:41
1

Please, check your config.yml + AppKernel.php

config.yml must be

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    naming_strategy: doctrine.orm.naming_strategy.underscore
    auto_mapping: true

or replace auto_mapping with

    mappings:
        StoreShopBundle: ~

for more, check this: https://stackoverflow.com/a/37652091/5809937

in AppKernel.php don't forget to check if bundle is activated:

        new MunichInnovationGroup\PatentBundle\MunichInnovationGroupPatentBundle(),
Community
  • 1
  • 1
Vladimir Ch
  • 487
  • 1
  • 12
  • 26
0

I had this when tried to use bandle name without core folder name. It was in config/security.yml

Folder structure in my case is the next src/Dp/UserBundle/....

I changed this `providers:

    main:
        entity: { class: UserBundle:User, property: username }`

to this `providers:

    main:
        entity: { class: DpUserBundle:User, property: username }`

So copy name of unknown Entity name and search each entries in project, check - they have to be with folder prefix (Dp in my case)

1nstinct
  • 1,745
  • 1
  • 26
  • 30
0

As at Symfony version 2.3.7, I used NameofCompanySomethingBundle:EntityRequired e.g. AcmeBlogBundle:User and it works.

auto-mapping: true (default) was used under orm: in config.yml.

Paul A.
  • 577
  • 2
  • 11
  • 24
0

This error will occur if you use multiple entity managers and you do not specify the entity manager in your controller function.

$em = $this->get('doctrine.orm.//your_entity_manager_name_here//_entity_manager');
$dql   = "SELECT ...";
$query = $em->createQuery($dql);

this worked for me.

sjt003
  • 2,407
  • 5
  • 24
  • 39
0

open your app\config.yml, must be

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: ~
Vega
  • 27,856
  • 27
  • 95
  • 103
Mr Ye
  • 1