简体   繁体   English

如何将自定义按钮/链接/锚添加到奏鸣曲管理菜单

[英]How to add custom button/link/anchor to sonata admin menu

First to say I'm new in sonata. 首先要说我是奏鸣曲的新手。 searched in docs, found similar problem here but not exactly the same. 在文档中搜索后,发现此处存在类似问题,但不完全相同。 I added Custom Admin not tied to any entity and added custom action: 我添加了不与任何实体绑定的自定义管理员,并添加了自定义操作:

namespace Opcja\AdminBundle\Admin;


class PriceProductAdmin extends AbstractAdmin
{
protected $baseRouteName = 'product_price';
protected $baseRoutePattern = 'product_price';


protected function configureRoutes(RouteCollection $collection)
{
    $collection->add('management');
}

} }

namespace Opcja\AdminBundle\Controller;

class PriceProductAdminController extends CRUDController
{
   public function managementAction()
   {
  //    return parent::listAction(); // TODO: Change the autogenerated stub
    return new Response("aa");
   }
}

Registered like in docs: 像在文档中一样注册:

        admin.price_product_admin:
        class: AdminBundle\Admin\PriceProductAdmin
        arguments: [~, ~, OpcjaAdminBundle:PriceProductAdmin]
        tags:
            - { name: sonata.admin, manager_type: orm, group: Products Price Management, label: Product Price }

Till here everything is ok, admin works, when i use '/management' route I see response from controller. 直到这里一切正常,管理员可以正常工作,当我使用'/ management'路由时,我看到了控制器的响应。 But in BlockMenu (left side "slide down") i can se group that I gave (Products....), I see Product Price when i click this group but the link goes to "/list" (I assume its default), I want this link to point to my custom action "/management" as I defined. 但是在BlockMenu(左侧“向下滑动”)中,我可以看到我给的组(“产品...”),当我单击该组时,我看到了产品价格,但链接转到了“ /列表”(我假设它是默认值) ,我希望此链接指向我定义的自定义操作“ / management”。

I checked these: 1. https://sonata-project.org/bundles/admin/master/doc/cookbook/recipe_custom_action.html 2. https://sonata-project.org/bundles/block/master/doc/reference/your_first_block.html and Im confused - I just want link in block menu to point into my custom action(management) instead of "list". 我检查了以下内容:1. https://sonata-project.org/bundles/admin/master/doc/cookbook/recipe_custom_action.html 2. https://sonata-project.org/bundles/block/master/doc/reference /your_first_block.html和我很困惑-我只希望块菜单中的链接指向我的自定义操作(管理)而不是“列表”。 Am I supposed to add new block? 我应该添加新块吗? create new directory and button (link 1, point 8.1.4 - tried this , it doesnt work for me)? 创建新目录和按钮(链接1,点8.1.4-尝试过此方法,对我而言不起作用)?

Try to add second parameter to configureRoutes method. 尝试添加第二个参数到configureRoutes方法。 Maybe it helps. 也许有帮助。

$collection->add('management', '/management');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM