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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:32:15+00:00 2026-06-04T14:32:15+00:00

I registered my services.yml file like below : services: PMI.form.users_tasks: class: PMI\UserBundle\Form\UsersTasksType arguments: EntityManager:

  • 0

I registered my services.yml file like below :

services:
  PMI.form.users_tasks:
        class: PMI\UserBundle\Form\UsersTasksType
        arguments: 
             EntityManager: "@doctrine.orm.default_entity_manager"

I can list it by php app/console container:debug, so that mean my service is registered properly.

In my UsersTasksType class I have like below :

class UsersTasksType extends AbstractType
{

    protected $ur;

    public function __construct(EntityManager  $ur )
    {
        $this->setUr($ur);
    }

    // Get and setters
}

Does Dependency Injection mean that I don’t have to pass the EntityManager to the class constructor anymore? Or what ?

Because when I have to run the code below :

$form   = $this->createForm(new UsersTasksType(), $entity);

I get this error:

Catchable Fatal Error: Argument 1 passed to PMI\UserBundle\Form\UsersTasksType::__construct() must be an instance of Doctrine\ORM\EntityManager, none given, called in C:\wamp\www\PMI_sf2\src\PMI\UserBundle\Controller\UsersTasksController.php on line 74 and defined in C:\wamp\www\PMI_sf2\src\PMI\UserBundle\Form\UsersTasksType.php line 19

And I have to do something below :

$em = $this->container->get('doctrine.orm.entity_manager');
$form   = $this->createForm(new UsersTasksType($em), $entity);

So what would be the whole purpose of Dependency Injection ?

  • 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-04T14:32:16+00:00Added an answer on June 4, 2026 at 2:32 pm

    Dependency Injection basically gives one service (in this case, your UserTasksType) access to another service (in this case, your the entity manager).

    arguments: 
         EntityManager: "@doctrine.orm.default_entity_manager"
    

    These two lines tell Symfony to expect the entity manager service to be passed into the constructor when you instantiate a new UserTasksType object, which effectively gives your UserTasksType access to the entity manager.

    If you aren’t using the entity manager in your UserTasksType, there is no need to inject it in the constructor and you could get rid of the two lines above and the __construct() / setUr() methods in your UserTasksType.

    A better example to help you understand DIC might be that you have a service that is written specifically to send emails (Swiftmail, for e.g.) and you need to inject it into another service so that service can send emails.

    By adding

    arguments: [ @mailer ]
    

    to your service definition, your services constructor will expect your mailer service

    __construct ($mailer)
    {
        $this->mailer = $mailer;
    }
    

    which will give it access to send emails

    someFunction()
    {
        //do something useful, then send an email using the swift mailer service
        $this->mailer->sendEmail();
    }
    

    Check out the latest Symfony docs for more of an explanation.

    http://symfony.com/doc/current/book/service_container.html

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

Sidebar

Related Questions

My Company registered in certain services on the Web and are relying on the
I'm currently using Silex for a small project. I've registered the form service that
I'd like to auto-register the common/simple services in my unity container. I think the
I have a basic class GenericHelper.php in directory Foo/BarBundle/Helper I registered it as a
I have an SSIS package on my desktop, which I registered to Integration Services
I have registered the log and added the source through the registry. ( HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<Log>\<Source>
I have an Eclipse product build using features. All of the services are registered
I get an Class not registered error whenever I attempt to connect to the
My company provide services to other websites. I would like to be able to
I registered account into oracle.com web site and I saw something very interesting: See

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.