0
votes

I had to make an entity called ProfileSchema with some fields, which one is Project_id. I needed to make a List, Edit, New, etc., for which I used the admin generator. The problem was as follows.

I have a list of projects, which they link to the list of the ProfileSchemas that have the same project_id, so I needed a route like: /backend/project/:project_id/ListProfileSchema

I couldn't find a way to do this with the admin generator (getting the project_id into the route), so I coded by hand all the routes (around 12, the new, edit, delete, batch actions, etc.), and change all the code generated by the admin generator to use the project_id passed as a parameter and the code generated by the adming generator as a guide.

==Questions==

  1. Is there a way more simple to do something like this?

  2. Now I need to add the confirmation JavaScript on the delete action on the actions of the list, which is generated by the method linkToDeleteMenu

    public function linkToDeleteMenu($object, $params){
        $url = url_for('project_delete_profile_schema', array('project_id' => $this->project_id, 'profile_schema_id' => $object->getId() )); 
        // $url = '/backend/project/1/DeleteProfileSchema/16'
            
        return link_to(__($params['label'], array(), 'sf_admin'), $url, $object, array('confirm' => !empty($params['confirm']) ? __($params['confirm'], array(), 'sf_admin') : $params['confirm'], 'project_id' => $this->project_id, 'profile_schema_id' => $object->getId()));
    }

The above code doesn't get the JavaScript. This code below generates the link well and it works, but I can't make the confirmation for the JavaScript appear.

return link_to(__($params['label'], array(), 'sf_admin'), $url, $object);

And the confirmation data is set, as replacing $url with $this->getUrlForAction('delete') does the trick but with the incorrect URL (the one generated by the admin generator).

By the way, I searched a lot trying to find something similar. The only similar question was this:

Routing exception in symfony ("The "/league/:id_league/members/new" route has some missing mandatory parameters (:id_league)")

But the answer didn't help me (as the default value is not dynamic and can't get to override it)

1

1 Answers

0
votes

I forgot to close this question. After some time i found that the solution was this:

return link_to('Delete', 'project_delete_profile_schema', array('project_id' => $object->getProjectId(), 'profile_schema_id' => $object->getId()), array( 'confirm' => !empty($params['confirm']) ? __($params['confirm'], array(), 'sf_admin') : $params['confirm']));

You pass the name displayed for the link as the 1st argument , the route name as the 2nd arguments, and the needed variables in the array in the 3rd parameter to generate the route. Finally, you pass the array to generate the confirmation code. My route is

project_delete_profile_schema:    
url:   /project/:project_id/DeleteProfileSchema/:profile_schema_id