gregorlee
gregorlee

Reputation: 13

How add new method in Sonata CRUD controller?

In CRUDController of SonataBundle are a lot of actions, for example listAction(), editAction() etc. For user managment is link:

http://site.local/app_dev.php/admin/sonata/user/user/list

and route for this:

admin_sonata_user_user_list       -  /admin/sonata/user/user/list

I would like add own action for this controller: listSecondAction();

I copy method listAction and change name to listSecondAction. Next i open

http://site.local/app_dev.php/admin/sonata/user/user/listSecond

and i have error:

No route found for "GET /admin/sonata/user/user/listSecond"

So how can i add and where routing for this action? How should i enter to this routing?

Upvotes: 1

Views: 3172

Answers (2)

rande
rande

Reputation: 666

Please review the current documentation: http://sonata-project.org/bundles/admin/master/doc/reference/routing.html#create-a-route

Upvotes: 1

Picoss
Picoss

Reputation: 2057

In your admin class you have to add configureRoutes method :

protected function configureRoutes(RouteCollection $collection) {
    $collection
        ->add('listSecond', 'listSecond')
        ->add('another', $this->getRouterIdParameter() . '/another');
    ;
}

And in your controller you need to add this two actions :

public function listSecondAction() {
    // Your code here
}

public function anotherAction($id = null) {
    // Here how to get the current object 
    $id = $this->get('request')->get($this->admin->getIdParameter());
    $object = $this->admin->getObject($id);
    // Your code here
}

Hope this helps

Upvotes: 2

Related Questions