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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:20:25+00:00 2026-06-09T08:20:25+00:00

I am having some trouble with Symfony2. Namely in how to use the __construct()

  • 0

I am having some trouble with Symfony2. Namely in how to use the __construct() function. the Official Documentation is shockingly bad!

I want to be able to use the following:

public function __construct()
{
    parent::__construct();
    $user = $this->get('security.context')->getToken()->getUser();
}

How ever I get the following error:

Fatal error: Cannot call constructor in /Sites/src/DEMO/DemoBundle/Controller/Frontend/HomeController.php on line 11

Line 11 is parent::__construct();. I removed it and got the following, new error

Fatal error: Call to a member function get() on a non-object in /Sites/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php on line 242

I think I might need to set up the ContainerInterface DIC, but I have no idea how to do this (I tried and failed, miserably)

Any ideas folks?

  • 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-09T08:20:26+00:00Added an answer on June 9, 2026 at 8:20 am

    This is actually quite a common misconception for new S2 developers. As @KingCrunch says, the S2 controller has no construct and thus your approach will fail. Take a look at the source code: namespace Symfony\Bundle\FrameworkBundle\Controller\Controller and you will see that the Controller extends component ContainerAware which has one method called setContainer. If you really wanted to, you could override this method and do what you want.

    However, there is an event system specifically designed for these sorts of things i.e. executing certain methods before the action method gets kicked off. Might want to search a bit for other questions on this topic.

    The S2.1 controller now has a getUser() method. I’d suggest adding it to your base controller class and not worrying about it.

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

Sidebar

Related Questions

im having some trouble with the following code: Ext.define('...controller...', { extend: 'Ext.app.Controller', init: function()
Im having some trouble writing a getstring function, this is what I have so
Having some trouble with the Migrations in Sequel and could use another set of
Im having some trouble with jQuery's slideToggle function in IE8 for some reason the
Having some trouble with some SQL. Take the following result for instance: LOC_CODE CHANNEL
Im having some trouble with an Array in C++. See I want to let
having some trouble passing a function as a parameter of another function... ERROR: Error
I'm having some trouble with this code. I am trying to write a function
Having some trouble with this.. <?php EG204_ExoSkel(); function EG204_ExoSkel() { $to_be_end = 'Red'; everything_loop();
Having some trouble getting this to work... I basically want the report to look

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.