I'm new to symfony2 and there are some things I don't get right now. In this case I want to display all albums made by a band or artist. If the user is logged in I want to display on the same page, if one album is in the collection of this user or not.
I've different bundles like "ArtistBundle", "UserBundle", "AlbumBundle" etc. Since the user related information is nothing which really belongs in the ArtistBundle ("separation of concerns") I want to get the information from the UserBundle.
Right now I see only two ways to do this:
<?php
namespace Acme/ArtistBundle/Controller;
use Acme/UserBundle/User
public function indexAction()
{
...
$user = new User($userId);
$collectionInfo = $user->checkArtistAlbums($artistId);
...
}
This solution might work but it makes unit tests harder since i'm not using dependency injection (which would be the correct way i think).
The other possibilty would be embedding the UserBundle controller in the template. Which can't be done since I need the information directly in the output of the ArtistBundle.
So what would be the "best practice" here? Defining a UserBundle Service? Somehow configure the ArtistBundle that an object of UserBundle is set in the construction of the object?
In my opinion I would create myProjectBundle. Then you create an Entity folder and there you create Album Artist and User folders. Inside you create Doctrine for each tables (album, atrtis, user).
What I would do is call service (create service folder and service class) in my controller (loginAction) that would pull information required (get all albums and artist for current user). Then use template to draw the login page and use another template to display rest of the information.