本文整理汇总了PHP中Sonata\AdminBundle\Admin\AdminInterface::getIdParameter方法的典型用法代码示例。如果您正苦于以下问题:PHP AdminInterface::getIdParameter方法的具体用法?PHP AdminInterface::getIdParameter怎么用?PHP AdminInterface::getIdParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Admin\AdminInterface
的用法示例。
在下文中一共展示了AdminInterface::getIdParameter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateMenuUrl
/**
* {@inheritdoc}
*/
public function generateMenuUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
{
// if the admin is a child we automatically append the parent's id
if ($admin->isChild() && $admin->hasRequest() && $admin->getRequest()->attributes->has($admin->getParent()->getIdParameter())) {
// twig template does not accept variable hash key ... so cannot use admin.idparameter ...
// switch value
if (isset($parameters['id'])) {
$parameters[$admin->getIdParameter()] = $parameters['id'];
unset($parameters['id']);
}
$parameters[$admin->getParent()->getIdParameter()] = $admin->getRequest()->attributes->get($admin->getParent()->getIdParameter());
}
// if the admin is linked to a parent FieldDescription (ie, embedded widget)
if ($admin->hasParentFieldDescription()) {
// merge link parameter if any provided by the parent field
$parameters = array_merge($parameters, $admin->getParentFieldDescription()->getOption('link_parameters', array()));
$parameters['uniqid'] = $admin->getUniqid();
$parameters['code'] = $admin->getCode();
$parameters['pcode'] = $admin->getParentFieldDescription()->getAdmin()->getCode();
$parameters['puniqid'] = $admin->getParentFieldDescription()->getAdmin()->getUniqid();
}
if ($name == 'update' || substr($name, -7) == '|update') {
$parameters['uniqid'] = $admin->getUniqid();
$parameters['code'] = $admin->getCode();
}
// allows to define persistent parameters
if ($admin->hasRequest()) {
$parameters = array_merge($admin->getPersistentParameters(), $parameters);
}
$code = $this->getCode($admin, $name);
if (!array_key_exists($code, $this->caches)) {
throw new \RuntimeException(sprintf('unable to find the route `%s`', $code));
}
return array('route' => $this->caches[$code], 'routeParameters' => $parameters, 'routeAbsolute' => $absolute);
}
示例2: aclAction
/**
* Returns the Response object associated to the acl action.
*
* @param int|string|null $id
*
* @return Response|RedirectResponse
*
* @throws AccessDeniedException If access is not granted.
* @throws NotFoundHttpException If the object does not exist or the ACL is not enabled
*/
public function aclAction($id = null)
{
if (!$this->admin->isAclEnabled()) {
throw new NotFoundHttpException('ACL are not enabled for this admin');
}
$id = $this->get('request')->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
}
if (false === $this->admin->isGranted('MASTER', $object)) {
throw new AccessDeniedException();
}
$this->admin->setSubject($object);
$aclUsers = $this->getAclUsers();
$adminObjectAclManipulator = $this->get('sonata.admin.object.manipulator.acl.admin');
$adminObjectAclData = new AdminObjectAclData($this->admin, $object, $aclUsers, $adminObjectAclManipulator->getMaskBuilderClass());
$form = $adminObjectAclManipulator->createForm($adminObjectAclData);
$request = $this->getRequest();
if ($request->getMethod() === 'POST') {
$form->submit($request);
if ($form->isValid()) {
$adminObjectAclManipulator->updateAcl($adminObjectAclData);
$this->addFlash('sonata_flash_success', 'flash_acl_edit_success');
return new RedirectResponse($this->admin->generateObjectUrl('acl', $object));
}
}
return $this->render($this->admin->getTemplate('acl'), array('action' => 'acl', 'permissions' => $adminObjectAclData->getUserPermissions(), 'object' => $object, 'users' => $aclUsers, 'form' => $form->createView()));
}
示例3: showAction
/**
* return the Response object associated to the view action
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showAction($id)
{
if (false === $this->admin->isGranted('SHOW')) {
throw new AccessDeniedException();
}
$object = $this->admin->getObject($this->get('request')->get($this->admin->getIdParameter()));
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
}
$this->admin->setSubject($object);
// build the show list
$elements = $this->admin->getShow();
return $this->render($this->admin->getShowTemplate(), array(
'action' => 'show',
'object' => $object,
'elements' => $this->admin->getShow(),
'admin' => $this->admin,
'base_template' => $this->getBaseTemplate(),
));
}
示例4: generateUrl
/**
* @throws \RuntimeException
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param $name
* @param array $parameter
* @param bool $absolute
* @return string
*/
public function generateUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false)
{
if (!$admin->isChild()) {
if (strpos($name, '.')) {
$name = $admin->getCode() . '|' . $name;
} else {
$name = $admin->getCode() . '.' . $name;
}
} else {
if ($admin->isChild()) {
$name = $admin->getBaseCodeRoute() . '.' . $name;
// twig template does not accept variable hash key ... so cannot use admin.idparameter ...
// switch value
if (isset($parameters['id'])) {
$parameters[$admin->getIdParameter()] = $parameters['id'];
unset($parameters['id']);
}
$parameters[$admin->getParent()->getIdParameter()] = $admin->getRequest()->get($admin->getParent()->getIdParameter());
}
}
// if the admin is linked to a parent FieldDescription (ie, embedded widget)
if ($admin->hasParentFieldDescription()) {
// merge link parameter if any provided by the parent field
$parameters = array_merge($parameters, $admin->getParentFieldDescription()->getOption('link_parameters', array()));
$parameters['uniqid'] = $admin->getUniqid();
$parameters['code'] = $admin->getCode();
$parameters['pcode'] = $admin->getParentFieldDescription()->getAdmin()->getCode();
$parameters['puniqid'] = $admin->getParentFieldDescription()->getAdmin()->getUniqid();
}
if ($name == 'update' || substr($name, -7) == '|update') {
$parameters['uniqid'] = $admin->getUniqid();
$parameters['code'] = $admin->getCode();
}
// allows to define persistent parameters
if ($admin->hasRequest()) {
$parameters = array_merge($admin->getPersistentParameters(), $parameters);
}
$route = $admin->getRoute($name);
if (!$route) {
throw new \RuntimeException(sprintf('unable to find the route `%s`', $name));
}
return $this->router->generate($route->getDefault('_sonata_name'), $parameters, $absolute);
}
示例5: editAction
/**
* return the Response object associated to the edit action
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* @param $id
* @return \Symfony\Component\HttpFoundation\Response
*/
public function editAction($id)
{
$object = $this->admin->getObject($this->get('request')->get($this->admin->getIdParameter()));
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
}
$this->admin->setSubject($object);
$form = $this->admin->getForm($object);
if ($this->get('request')->getMethod() == 'POST') {
$form->bindRequest($this->get('request'));
if ($form->isValid()) {
$this->admin->update($object);
if ($this->isXmlHttpRequest()) {
return $this->renderJson(array('result' => 'ok', 'objectId' => $object->getId()));
}
// redirect to edit mode
return $this->redirectTo($object);
}
}
return $this->render($this->admin->getEditTemplate(), array('action' => 'edit', 'form' => $form->createView(), 'object' => $object, 'admin' => $this->admin, 'base_template' => $this->getBaseTemplate()));
}
示例6: aclAction
/**
* Returns the Response object associated to the acl action.
*
* @param int|string|null $id
* @param Request $request
*
* @return Response|RedirectResponse
*
* @throws AccessDeniedException If access is not granted.
* @throws NotFoundHttpException If the object does not exist or the ACL is not enabled
*/
public function aclAction($id = null)
{
$request = $this->getRequest();
if (!$this->admin->isAclEnabled()) {
throw $this->createNotFoundException('ACL are not enabled for this admin');
}
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id : %s', $id));
}
$this->admin->checkAccess('acl', $object);
$this->admin->setSubject($object);
$aclUsers = $this->getAclUsers();
$aclRoles = $this->getAclRoles();
$adminObjectAclManipulator = $this->get('sonata.admin.object.manipulator.acl.admin');
$adminObjectAclData = new AdminObjectAclData($this->admin, $object, $aclUsers, $adminObjectAclManipulator->getMaskBuilderClass(), $aclRoles);
$aclUsersForm = $adminObjectAclManipulator->createAclUsersForm($adminObjectAclData);
$aclRolesForm = $adminObjectAclManipulator->createAclRolesForm($adminObjectAclData);
if ($request->getMethod() === 'POST') {
if ($request->request->has(AdminObjectAclManipulator::ACL_USERS_FORM_NAME)) {
$form = $aclUsersForm;
$updateMethod = 'updateAclUsers';
} elseif ($request->request->has(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME)) {
$form = $aclRolesForm;
$updateMethod = 'updateAclRoles';
}
if (isset($form)) {
$form->handleRequest($request);
if ($form->isValid()) {
$adminObjectAclManipulator->{$updateMethod}($adminObjectAclData);
$this->addFlash('sonata_flash_success', 'flash_acl_edit_success');
return new RedirectResponse($this->admin->generateObjectUrl('acl', $object));
}
}
}
return $this->render($this->admin->getTemplate('acl'), array('action' => 'acl', 'permissions' => $adminObjectAclData->getUserPermissions(), 'object' => $object, 'users' => $aclUsers, 'roles' => $aclRoles, 'aclUsersForm' => $aclUsersForm->createView(), 'aclRolesForm' => $aclRolesForm->createView()), null, $request);
}
示例7: historyViewRevisionAction
/**
* @param null $id
* @param string $revision
*
* @return Response
*/
public function historyViewRevisionAction($id = null, $revision = null)
{
if (false === $this->admin->isGranted('EDIT')) {
throw new AccessDeniedException();
}
$id = $this->get('request')->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
}
$manager = $this->get('sonata.admin.audit.manager');
if (!$manager->hasReader($this->admin->getClass())) {
throw new NotFoundHttpException(sprintf('unable to find the audit reader for class : %s', $this->admin->getClass()));
}
$reader = $manager->getReader($this->admin->getClass());
// retrieve the revisioned object
$object = $reader->find($this->admin->getClass(), $id, $revision);
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the targeted object `%s` from the revision `%s` with classname : `%s`', $id, $revision, $this->admin->getClass()));
}
$this->admin->setSubject($object);
return $this->render($this->admin->getShowTemplate(), array('action' => 'show', 'object' => $object, 'elements' => $this->admin->getShow()));
}