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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:45:22+00:00 2026-06-13T11:45:22+00:00

Using symfony2 I am following this documentation to create and use a service for

  • 0

Using symfony2 I am following this documentation to create and use a service for performing a general task.

I have it almost done, but I have one problem yet (surely due to some misunderstanding on service containers in Symfony2.

The class is something like this:

class MyClass{
    private $myProperty;

    public funciton performSomethingGeneral{
        return $theResult;
    }
}

Now, in my config.yml:

services:
    myService:
        class: Acme\MyBundle\Service\MyClass
        arguments: [valueForMyProperty]

Finally, in my controller:

$myService = $this -> container -> get('myService');

After that line, When I inspect $myService, I still see $myService -> $myProperty as uninitialized.

There is something I am not getting properly. What else do I have to do to get the property initialized and ready to use with a previously configured value in config.yml? And how would I set more than one property?

  • 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-13T11:45:23+00:00Added an answer on June 13, 2026 at 11:45 am

    arguments from your yml file are passed to the constructor of your service, so you should handle it there.

    services:
        myService:
            class: Acme\MyBundle\Service\MyClass
            arguments: [valueForMyProperty, otherValue]
    

    and php:

    class MyClass{
        private $myProperty;
        private $otherProperty;
    
        public funciton __construct($property1, $property2){
             $this->myProperty = $property1;   
             $this->otherProperty = $property2;   
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a weird problem with twig in Symfony2. I am using the following
I am using a login form on Symfony2 with the following controller code public
I have an example where I am trying to create an AJAX login using
I'm developing a simple page with Symfony2, using Twig as template engine. I have
Using symfony 1.4. I have the following widget declaration in my form: 'region' =>
I'm using Symfony2 and CraueFormFlowBundle to create a multi-step form. Everything is going well
I am working on a simple forum in symfony2 and have the following DQL
I recently create a website (following the french tutorial http://www.siteduzero.com/tutoriel-3-517569-symfony2-un-tutoriel-pour-debuter-avec-le-framework-symfony2.html ). Now everything is
Following this tutorial i'm developing a web application using symfony authentication/authorization architecture. After designing
I am using Symfony 1.3 and I have the following problem: I need a

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.