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 8543475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:18:38+00:00 2026-06-11T12:18:38+00:00

Take a look to that code <?php namespace Sestante\SestanteBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use

  • 0

Take a look to that code

<?php

namespace Sestante\SestanteBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sestante\SestanteBundle\Model\StrutturaManager;

class MainController extends Controller
{
    public function indexAction(Request $request)
    {
        return $this->render('SestanteSestanteBundle:Main:index.html.twig');
    }

    public function showLodgingsAction(Request $request)
    {
        $repo = $this->getDoctrine()->getRepository('SestanteSestanteBundle:Struttura');
        $usr = $this->get('security.context')->getToken()->getUser();
        $usrId = $usr->getId();
        $sm = new StrutturaManager($repo);
        $lodgingList = $sm->retrieveLodgingsFromUser($usrId);
        return $this->render('SestanteSestanteBundle:Main:showLodgings.html.twig',array('lodgingList' => $lodgingList));
    }
}

This is a controller for an application that I’ve been writing.

Take a look to showLodgingsAction. I’ve tryied to place all business logic into a model (StrutturaManager) that with a repository (that I’ve passed directly from controller because, as far I know, they’re available only here or via D.I.) query my db, do some elaboration and return a list that I’ll render onto a template.

First question: Is this “code separation” good, or exists a better way for do what I’m trying to do?

Second question: suppose that, now, I want to use an object of StrutturaManager type into indexAction. Remember that mine object want a repository. So, have I to declare again, and again, and again, all my object for every controller’s action where I want to use them? I suppose that must exist a smarter method but, at the moment, I don’t understand which.

  • 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-11T12:18:39+00:00Added an answer on June 11, 2026 at 12:18 pm

    Define StrutturaManager as a service and inject the EntityManager into it. This way the manager will have access to repositories you need and controllers won’t know about Doctrine nor repositories — which is a good practice.

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

Sidebar

Related Questions

Take a look that the following code snippet: A a = null try {
I'm writing a PHP function that would use a table of sorts to look
I'm trying to build a PHP form that outputs custom JSON code. Take a
Please take a look at the following autocomplete code. $(document).ready(function(){ $(#the_input).autocomplete(/autocomplete.php, { //some options
Example: http://bit.ly/dfjvmT If you take a look at that URL, you will see an
Take a look at this screenshoot first: That white box is ON the orange
Please take a look here: alt text http://img16.imageshack.us/img16/2810/errrp.jpg Why i got that error when
Link: http://www.fraynepainting.com/services The problem is that div#dditem_2 (the div with the Take a look...
Am I doing this right? I went to look at some old PHP code
Take a look at this code and please tell me how is it possible

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.