Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:33:11+00:00 2026-06-13T07:33:11+00:00

With doctrine2 , i created my entities in Entities folder. Folder: ./ HelloEntity.php WorldEntity.php

  • 0

With doctrine2, i created my entities in Entities folder.

Folder:

./
    HelloEntity.php
    WorldEntity.php

I created my structure in PHP and import them:

$namespaceYaml = array($connection->getBundle()->getNamespace() => $bundleFolder.'/Entity/ORM/');
$driver = new YamlDriver($namespaceYaml, '.orm.yml');
$path = $bundleFolder.'/Resource/config/doctrine/metadata/orm';
$config = Setup::createYAMLMetadataConfiguration(array($path), true);
$config->setEntityNamespaces(array($connection->getBundle()->getName() => $connection->getBundle()->getNamespace().'\Entity'));
$config->setMetadataDriverImpl($driver);

Now, it is working. I can use them.

For example:

$qb = $this->getRepository()->createQueryBuilder('Hello'); //short here but long in from()
$qb->from('MyWeb\Entities\Hello', 'h'); //Hello Entity

Now, MyWeb is my main root/namespace. When i want to use doctrine with my tables, i have to write MyWeb\Entities\Hello. All i want to do is shorten them. Can’t i just use 'Hello'

Does anyone have any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:33:13+00:00Added an answer on June 13, 2026 at 7:33 am

    For now, i found the answer on somewhere else on StackOverflow. It is not the same question but looks like it answers both.

    Shortly, We have to use fully qualified namespaces for table names instead of short one. But we can use short names when we get the repository (besides bundle name)

    Refer: Doctrine DQL and Namespaces (relative only?)

    Now, i found the answer.

    Answer:

    My previous solution is correct. We have to use fully qualified namespaces minus slash at the first str.

    But, we can also use it by short.

    See, every entityManmager has an Repository and we can get it by using $em->getRepository(). After that, with createQueryBuilder('e') (attention to “e” here) generates HelloEntity name itself and assign it to the e alias.

    So, my code was wrong and no need to enter namespace 🙂

    Conclusion:

    Instead of this:

    $qb = $this->getRepository()->createQueryBuilder('Hello'); //short here but long in from()
    $qb->from('MyWeb\Entities\Hello', 'h'); //Hello Entity
    

    Use this:

    $qb = $this->getRepository()->createQueryBuilder('h'); //h assigned for Hello table and HelloEntity. So no need for from. It will fetch data two times then.
    

    Solved.

    Fix and idea came from: Doctrine2 fetch 5 copy of each record

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such doctrine entities: <?php namespace App\Entity; use Doctrine\Common\Collections\ArrayCollection; /** * @Entity(repositoryClass=App\Repository\Page) *
I'm trying to regerate slug for entities that I've created prior to install Sluggable
Hi have setup a db with tables States and StoreLocations. I have created entities
Typically i create my entities in symfony2/doctrine from this console commands : $php app/console
How can I add my custom driver without modifying DriverManager.php in the Doctrine2 core?
I am a little bit confused with Doctrine class. I created a class and
Doctrine2 docs said that soft-delete behavior should be better implemented as a State pattern
The Doctrine2 DQL allows for the following SQL : $query = $em->createQuery('SELECT u.id FROM
I am using Doctrine2 migrations. I need some answers about my doubt, I canno
I'm actually using Doctrine2 within a Zend Framework project. I'm build an API to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.