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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:28:26+00:00 2026-06-06T16:28:26+00:00

I have a REST API built with Symfony2 and the FOSRestBundle. This all works

  • 0

I have a REST API built with Symfony2 and the FOSRestBundle. This all works fine, however in one service I combine data form another service in a different bundle – this seemed like it would be simple but it is not.

I am creating a new request object and adding in my parameters, from there I fire off the request to the other service, the service receives the request fine, however, when I try to use $this->get it gives me the good old Call to a member function get() on a non-object in ...

I know that I am missing the service container (I don’t entirely understand why it’s available when I call a hit the first bundle but not the second), that’s all well and fine but how do I inject it or a component of it so I can use $this->get to hit my custom services defined in services.yml? (easy to pass them the service container using arguments:
container: "@service_container"
)

Setting this bundle up as a service won’t work as FOSRestBundle does not call it as a service.

In Short: I want to be able to get data from bundle2 when inside bundle1 by doing

namespace MyVendor\Bundle1\Controller

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;  
use MyVendor\Bundle2\Controller\Bundle2ClassName;

class Bundle1 {

    //if i wanted to do this here it would work fine:
    // $this->get('my.service.defined.in.service.yml');

    $bundle2 = new Bundle2ClassName();
    $returned_data = $bundle2->myFunction();
}

Then once inside myFunction in bundle2 if I try to call the exact same service function i get the dreaded get error. If I call bundle2 directly through the FOSRest route i obviously don’t have that problem.

namespace MyVendor\Bundle2\Controller

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;  

class Bundle2 {

    //this does not work
    $this->get('my.service.defined.in.service.yml');

    //do some stuff then return response
    return($response);

}     

I’ve read all the service container docs over and over again, so if you’re going to link to them i’d appreciate it if you could point out the exact section where it explains how this stuff is handled. This has been the one problem i’ve never been able to fully understand since I started working with Symfony a few months back.

P.S. could someone with enough points add the FOSRestBundle as a tag?

Thanks!

  • 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-06T16:28:28+00:00Added an answer on June 6, 2026 at 4:28 pm

    First of all you should use $this->forward to forward request to another controller.

    Second, the reason you don’t have access to service container in second controller is probably because you’re trying to manually initialize it – never do that unless you absolutely know what you’re doing (specifically, you forgot to pass service container as controller dependency).

    Third, just as an example on how things work – your original controller dependency on service container is handled by the same container and extends ContainerAware, on that controller initialization a setContainer() is called, which you most likely forgot to do when manually initializing second controller. So to get it working (which again I strongly recommend not doing), you should do this:

    class Bundle1 {
    
        //if i wanted to do this here it would work fine:
        // $this->get('my.service.defined.in.service.yml');
    
        $bundle2 = new Bundle2ClassName();
        $bundle2->setContainer($this->container);
        $returned_data = $bundle2->myFunction(); 
    }
    

    The reason you’re getting the $this->get() on a non-object... error is because $this->get() in your controller is actually a shortcut to $this->container->get() (defined in Symfony\Bundle\FrameworkBundle\Controller\Controller)

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

Sidebar

Related Questions

I have an NSArray built from json data from twitter REST API. NSArray *dict
I have built a REST API backend whith Spring MVC and secured with basic
I have a REST api which dumps some json data (user info, etc). Now
im trying to send rest api Users.getLoggedInUser i have all the secret session and
I'm using django-piston for my REST json api, and I have it all set
I have a REST service built using Jersey . When I performed a curl
I have some issue regarding REST API which i have built using servicestack. End
I have a scenario in which I have REST API which manages a Resource
We have a REST API where clients can supply parameters representing values defined on
Say I have a REST API in java, and it supports responses that are

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.