错误:没有为控制器定义`_sonata_admin` [英] Error: There is no `_sonata_admin` defined for the controller
问题描述
我按照文档添加自定义路由.当我单击列表视图中的按钮时,出现错误:
I followed the documentation for adding a custom route. When I click on the button in the list view, I get the error:
没有为控制器***\UserController
和当前路由resetPassword
There is no
_sonata_admin
defined for the controller***\UserController
and the current routeresetPassword
文档: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]]
我已经在我的 UserAdmin 中添加了我的路由
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
}
}
如果我手动浏览或通过 ajax 调用(我们的应用程序在另一点执行此操作),该路由可以正常工作.但是,当我尝试单击在 UserAdmin 的 configureListFields() 中生成的列表视图中的按钮时,出现主题错误.我无法弄清楚任何其他默认操作如何将代码放入请求中,它们看起来与这个相同.当我用谷歌搜索错误时,我发现其他一些人问这个问题,但我的管理员似乎配置正确,这是我能找到的唯一答案 - 它似乎过时了,因为现在参数似乎有不同的顺序.
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.
推荐答案
它唯一的想法,未经测试 - 也许您必须有与路由名称(而不是模式字符串)对应的控制器操作:password_reset -> passwordResetAction
Its only idea, not tested - maybe you must have controller action coresponding with route name (not with pattern string): password_reset -> passwordResetAction
这篇关于错误:没有为控制器定义`_sonata_admin`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!