Hallel
Hallel

Reputation: 425

relations between controllers in Symfony2

I'm writing a web-application in symfony2 for the first time. i've just decided to split my server-side into several controllers. i'm creating my base object in my default controller and as the user makes some choices and the data gets more specific I want to handle it (each data-class) in a different controller. for that to happen in need to tie the new subclass to it's base class. something like

// default controller
class DefaultController extends Controller
{
    public $trip;

    public function startAction()
    {
        // get data from request etc.
        // ...
        $trip = new Trip();
    }

    // handling everything else
 }

and then,

// stage controller
class StageController extends Controller
{
    public $stage;

    public function setStageAction()
    {
        // get data from request etc.
        // ...
        $stage = new Stage();
        $stage->SetTrip($trip); // doesn't work of course.
    }

    // handling everything else
 }

trying to figure out how to handle the situation above i've been wondering what's the relations of the controllers within a bundle is like. couldn't find nothing but "set the controller as a service" which may be a solution to my situation but doesn't help me understand the architecture. i guess maybe it's a dumb question, still, anyone?

Upvotes: 0

Views: 80

Answers (1)

ghostika
ghostika

Reputation: 1503

In symfony you can use services for this.

Every service will do the job, what you delegate to it. For exmaple, there is a service called StageManager, then you create there a function create Stage, wher you do all your entity creation and mapping and then you can persist it to the database.

Here you can see an example what is a service, how can you create one and how to use it in a controller.

Link

Upvotes: 0

Related Questions