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

  • Home
  • SEARCH
  • 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 7557987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:16:26+00:00 2026-05-30T12:16:26+00:00

I’m trying to understand Zend Framework 2. For that, I started with Ron Allen’s

  • 0

I’m trying to understand Zend Framework 2.
For that, I started with Ron Allen’s tutorial http://akrabat.com/getting-started-with-zend-framework-2/
then, I integrate doctrine 2, using the tutorial http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/
ok, before that I decide to make it more complex.

I change the database to the following:

--
-- Estrutura da tabela `album`
--
CREATE TABLE IF NOT EXISTS `album` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `artist_id` int(11) NOT NULL,
  `title` varchar(100) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `artist` (`artist_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;

--
-- Estrutura da tabela `artist`
--
CREATE TABLE IF NOT EXISTS `artist` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

My application have this structure:

module
    Album
        src
            Album
                Controller
                    AlbumController.php
                Entity
                    Album.php
    Artist
        src
            Artist
                Controller
                    ArtistController.php
                Entity
                    Artist.php

My new Entities are like that:

class Album {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer");
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $title;

    /**
     * @ORM\ManyToOne(targetEntity="Artist", inversedBy="album")
     * @ORM\JoinColumn(name="artist_id", referencedColumnName="id")
     */
    protected $artist;

    ...
}
class Artist {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer");
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $name;

    /**
     * @ORM\OneToMany(targetEntity="Album", mappedBy="artist")
     */
    protected $album;


    public function __construct()
    {
        $this->album = new ArrayCollection();
    }

    ...
}

But It doesn’t work!
I got this mensage:

"The target-entity Album\Entity\Artist cannot be found in 'Album\Entity\Album#artist'."

So my question is: What is wrong? My Entities are in the wrong place? or my module organization are not ok?
How can I make one entity be visible for more than one module?

UPDATE:

I change my entities to:

class Album {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer");
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $title;

    /**
     * @ORM\ManyToOne(targetEntity="\Artist\Entity\Artist", inversedBy="album")
     * @ORM\JoinColumn(name="artist_id", referencedColumnName="id")
     */
    protected $artist;

    ...
}
class Artist {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer");
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $name;

    /**
     * @ORM\OneToMany(targetEntity="\Album\Entity\Album", mappedBy="artist")
     */
    protected $album;

    ...
}

But I got the same error:

"The target-entity Artist\Entity\Artist cannot be found in 'Album\Entity\Album#artist'."

UPDATE 2:

I changed the structure of my application to:

module
    Album
        src
            Album
                Controller
                    AlbumController.php
                    ArtistController.php
                Entity
                    Album.php
                    Artist.php

so my entities are in the same namespace and now my program it’s working! =)

But I still have the question: how can I make one entity to be visible to more than one mudule in ZF2?

  • 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-05-30T12:16:27+00:00Added an answer on May 30, 2026 at 12:16 pm

    I found the answer! =D

    I got to wait 8 hours to answer my own question, so here we go.

    As I said, I reproducing the tutorial http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/

    They teach how to configure the module to work with Doctrine 2.
    In the file module/Album/config/module.config.php they insert the following code:

    return array(
        'di' => array(
            'instance' => array(
                // ...
                'orm_driver_chain' => array(
                    'parameters' => array(
                        'drivers' => array(
                            'Album' => array(
                                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                                'namespace' => __NAMESPACE__ . '\Entity',
                                'paths' => array(
                                    __DIR__ . '/../src/' . __NAMESPACE__ . '/Entity'
                                ),
                            ),
                        ),
                    ),
                ),
    

    According to the tutorial:

    “This tells Doctrine that the Album module’s entities use the namespace
    Album\Entity, and that the classes in that namespace are stored in
    $PROJECT_DIR/module/Album/src/Album/Entity.”

    so, there is the problem!
    Doctrine was configure to use only Album\Entity!
    so I changed the code to the following (with bad programming… sorry):

    //...
    'drivers' => array(
        'Album' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'namespace' => __NAMESPACE__ . '\Entity',
            'paths' => array(
                __DIR__ . '/../src/' . __NAMESPACE__ . '/Entity'
            ),
        ),
        'Artist' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'namespace' => '\Artist\Entity',
            'paths' => array(
                __DIR__ . '/../../Artist/src/Artist/Entity'
            ),
        ),
    //...
    

    As you can see I configure an ‘Artist’ driver…

    Now my application work properly! =)

    I’m still looking for the right way to configure the doctrine in my application but at least I got the answer!

    Thanks for everybody! 🙂

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.