dplsnw7329 2017-11-13 09:28
浏览 91
已采纳

自定义操作页面Sonata Admin

I'm looking to create a new action page for my sonata admin project. I want to make a page where to upload files, but I want this page to be different than create page. I tried to change configureRoutes function and I added '/upload/ path just like in Sonata tutorial, but they are telling me to use getRouterIdParameter() and I don't want something like /app/class/<ID>/upload. I just want to something like /app/class/upload.

It's that possible ?

  • 写回答

1条回答 默认 最新

  • duanji2772 2017-11-13 11:42
    关注
    1. CRUD - Create, Read, Update, Delete. So, CRUD controllers work with defined object. When you create actions in your CRUD controller you have to get the object, otherwise - your action won't know which object to create, update, delete, etc.
    2. That's why you should to put object's id to your route.

      public function superAction(Request $request, $id = null)
      {
          try {
              if ($id !== null) {
                  $yourObject = $this->admin->getObject($id);
              }
          } catch (NotFoundHttpException $e) {
              error_log($e->getMessage());
          }
      
          //... your logic
      
      }
      

    But! If your action doesn't supposed to use particular object - you can avoid object $id in your route. Also you are able to pass the variables with GET method. As many as you wish.

    Imagine, that you want to update all your objects. Then you can create updateAllAction() and then add this route:

    /**
     * @param RouteCollection $collection
     */
    protected function configureRoutes(RouteCollection $collection)
    {
        $collection->add('updateAll', 'update/all');
    }
    

    As long as your action doesn't care of the particular object you can avoid $this->getRouterIdParameter() in your uri.

    Hope it is helpful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度