gpt4 book ai didi

php - 错误 : There is no `_sonata_admin` defined for the controller

转载 作者:行者123 更新时间:2023-12-03 18:38:54 25 4
gpt4 key购买 nike

我按照文档添加自定义路由。当我点击 ListView 中的按钮时,出现错误:

There is no _sonata_admin defined for the controller ***\UserController and the current route resetPassword

文档:http://sonata-project.org/bundles/admin/master/doc/reference/routing.html

我的管理服务定义如下:

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 中添加了我的路线

  protected function configureRoutes(RouteCollection $collection)
{
parent::configureRoutes($collection);
$collection->add('password_reset', $this->getRouterIdParameter() . '/resetPassword/');
}

并创建了自定义 Controller 和操作。

  <?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() 中生成的 ListView 中的按钮时,出现了主题错误。我无法弄清楚其他任何默认操作是如何将代码放入请求中的,它们看起来和这个一样。当我用谷歌搜索错误时,我发现其他一些人问过这个问题,但我的管理员似乎配置正确,这是我能找到的唯一答案——而且它似乎已经过时了,因为现在参数似乎处于不同的顺序。

在此先感谢你们提供的任何帮助。

最佳答案

这是唯一的想法,未经测试 - 也许您必须让 Controller 操作与路由名称(而不是模式字符串)对应:password_reset -> passwordResetAction

关于php - 错误 : There is no `_sonata_admin` defined for the controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20288729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com