问题
I followed the documentation for adding a custom route. When I click on the button in the list view, I get the error:
There is no
_sonata_admin
defined for the controller***\UserController
and the current routeresetPassword
The docs: http://sonata-project.org/bundles/admin/master/doc/reference/routing.html
My Admin Service is defined as follows:
sonata.admin.user:
class: ****\Admin\UserAdmin #User Admin
tags:
- { name: sonata.admin, model_manager: cems_model_manager, manager_type: orm, group: core, label: "Users" }
arguments:
- ~
- models\User #User Model
- '****Bundle:User' #User Controller
calls:
- [ setTranslationDomain, [****Bundle]]
I have added my route in my UserAdmin
protected function configureRoutes(RouteCollection $collection)
{
parent::configureRoutes($collection);
$collection->add('password_reset', $this->getRouterIdParameter() . '/resetPassword/');
}
And created the custom controller and action.
<?php
namespace ****\Controller;
use Sonata\AdminBundle\Controller\CRUDController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
class UserController extends CRUDController
{
/**
* @Route("/User/{userId}/resetPassword/", name="resetPassword")
*/
public function resetPasswordAction(Request $request, $userId)
{
// code here
}
}
The route works fine if I browse to it manually or via an ajax call, which our application does at another point. But when I try to click on the button in the list view, which is generated in the configureListFields() in UserAdmin, I get the subject error. I can't figure out how any of the other default actions put the code into the request, they look the same as this one does. I found a few other people asking this question when I googled the error but my admin appears to be configured correctly, and that was the only answer I could find - and it seems outdated as the arguments appear to be in different orders now.
Thanks in advance for any help you guys can provide.
回答1:
Its only idea, not tested - maybe you must have controller action coresponding with route name (not with pattern string): password_reset -> passwordResetAction
回答2:
There is no need to @Route("/User/{userId}/resetPassword/", name="resetPassword")
since its defined before in configureRoutes function.
来源:https://stackoverflow.com/questions/20288729/error-there-is-no-sonata-admin-defined-for-the-controller