简体   繁体   English

如何使用Symfony在奏鸣曲管理员中通过自定义动作进行自定义路线

[英]How to make custom route with custom action in sonata admin using Symfony

我是Symfony和Sonata管理员的新手,我想在Sonata admin中使用自定义操作创建自定义路由。任何人都知道如何通过自定义操作创建自定义路由以及如何从twing文件中调用该自定义路由?

Example of route in your AdminBundle: AdminBundle中的路由示例:

<route id="get_driver_location" path="/driver-location">
    <default key="_controller">MyAdminBundle:Core:getlocation</default>
</route>

Then you must create a controller called CoreController in the controller directory of your bundle 然后,您必须在包的controller目录中创建一个名为CoreController的控制器

    namespace My\AdminBundle\Controller;

    use Symfony\Component\Config\Definition\Exception\Exception;
    use Symfony\Component\HttpFoundation\Response;
    use Sonata\AdminBundle\Controller\CoreController as BaseController;

    class CoreController extends BaseController {

    public function getlocationAction() {
        //your logic here
       ......
       return $this->render($this->getAdminPool()->getTemplate('driver'), array(
                    'base_template' => $this->getBaseTemplate());
    }

    }

Edit: Add Twig: 编辑:添加树枝:

-Resources

  -views

    -Core

      -driver.html.twig

in the file driver.html.twig you make a route 在文件driver.html.twig中,您可以进行路由

<div>
                <a class="btn btn-default" href="{{ path('get_driver_location') }}" role="button">
                    {{ "example"|trans({}, "MyAdminBundle") }}
                </a>
            </div>

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

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