1
votes

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
How you have defined curd controller action for this route ? - M Khalid Junaid
@MKhalidJunaid, yes, I did. - GasKa

1 Answers

0
votes
  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.