Reputation: 1251
I am trying to display different Events
on a calendar in one of my SonataAdmin Entities.
I have 2 services, Practice and Event:
bm.user.admin.practice:
class: BM\UserBundle\Admin\PracticeAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: cvp_users, label: Practice }
arguments: [bm.user.admin.practice, BM\UserBundle\Entity\Practice, BMUserBundle:PracticeAdmin]
and
bm.crm.admin.event:
class: BM\CrmBundle\Admin\EventAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: cvp_users, label: Schedule }
arguments: [bm.crm.admin.event, BM\CrmBundle\Entity\Event, BMCrmBundle:EventAdmin]
The calendar is displayed in the editAction
of the Practice
My problem is, I'm trying to get results from an action in the EventAdminController
/**
* Fetch Events based on User.
*
* @Route("/admin-events-create/{id}", name="create_event", options={"expose"=true})
* @Method("GET|POST")
* @Template()
*/
public function fetchEventsAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('BMUserBundle:User')->find($id);
$events = $em->getRepository('BMCrmBundle:Event')->findAllEventsByUser($user->getId());
}
I'm trying to call this using the following:
{{ path('fetch_events', { _sonata_admin: 'bm.crm.admin.events'} ) }}
But that is missing the id
that I need to use in the controller.
Changing it to:
{{ path('fetch_events', { id: 'myObj.id', _sonata_admin: 'bm.crm.admin.event'} ) }}
or anything similar always gives me:
There is no
_sonata_admindefined for the controller
Any ideas on how I can pass the id
value I need to the route?
Thanks
Upvotes: 2
Views: 4029
Reputation: 456
I think that error is in path
{{ path('fetch_events', { 'id': object.id } ) }}
Sonata custom route is prefixed with base route name of admin:
{{ path('your_admin_base_route_name_fetch_events', { 'id': object.id } ) }}
short name of custom route can be used for URL generated by admin method
admin.generateUrl('fetch_events', { 'id': object.id } )
Upvotes: 0
Reputation: 930
First in EventAdmin class
use Sonata\AdminBundle\Route\RouteCollection;
then add method
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('fetch_events', '{id}/fetch_events');
}
You can check declared routes for admin class if you are on *nix system with grep:
php app/console router:debug | grep events
use it as
{{ path('fetch_events', { 'id': object.id } ) }}
Upvotes: 1