本文整理汇总了PHP中Symfony\Component\Routing\Router::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::generate方法的具体用法?PHP Router::generate怎么用?PHP Router::generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Router
的用法示例。
在下文中一共展示了Router::generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createSubjectTreeView
/**
* @param $type
* @param Router $router
* @param ArrayCollection|Subject[] $subjects
* @param int|null $parentId
* @return string
*/
public static function createSubjectTreeView($type, $router, $subjects, $parentId = null)
{
$tree = '<ul>%s</ul>';
$item = '<li>%s</li>';
$link = '<a href="%s">%s</a>';
$items = "";
/**
* @var Subject $subject
* @var ArrayCollection $children
*/
foreach ($subjects as $subject) {
if ($subject->getParent() === null || $subject->getParent()->getId() === $parentId) {
if ($type == TreeHelper::SUBJECT_ADMIN) {
$path = $router->generate('ojs_admin_subject_show', ['id' => $subject->getId()]);
} else {
$path = $router->generate('ojs_search_index', ['subject_filters' => $subject->getSubject()]);
}
$content = sprintf($link, $path, $subject->getSubject());
$children = $subject->getChildren();
if ($children->count() > 0) {
$content = $content . TreeHelper::createSubjectTreeView($type, $router, $children, $subject->getId());
}
$items = $items . sprintf($item, $content);
}
}
return sprintf($tree, $items);
}
示例2: handle
public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();
$wsseHeader = $request->headers->get(self::WSSE_HEADER, false);
if (!$wsseHeader || 1 !== preg_match(self::WSSE_REGEX, $wsseHeader, $matches)) {
$event->setResponse(new Response('', Response::HTTP_FORBIDDEN, array('WWW-Authenticate' => 'WSSE realm="webservice", profile="ApplicationToken"')));
return;
}
$token = new TelenorUserToken($this->providerKey, $matches[2], $matches[3], $matches[4]);
$token->setUser($matches[1]);
try {
$authenticatedToken = $this->authenticationManager->authenticate($token);
$this->securityContext->setToken($authenticatedToken);
return;
} catch (NonceExpiredException $failed) {
$this->logger->debug("Nonce expired: " . $wsseHeader);
} catch (AuthenticationException $failed) {
$this->logger->debug("Authentication failed: " . $failed->getMessage());
}
$token = $this->securityContext->getToken();
if ($token instanceof TelenorUserToken) {
$this->securityContext->setToken(null);
}
$response = new Response("", Response::HTTP_UNAUTHORIZED, array(Headers::LOCATION => $this->router->generate('telenor.authentication.login')));
$event->setResponse($response);
}
示例3: __construct
public function __construct(Session $session, Router $router, $environement, $merchant_pos_id, $pos_auth_key, $client_id, $client_secret, $signature_key)
{
$this->session = $session;
$this->session->start();
$this->environment = $environement;
$this->merchantPosId = $merchant_pos_id;
$this->posAuthKey = $pos_auth_key;
$this->clientId = $client_id;
$this->clientSecret = $client_secret;
$this->signatureKey = $signature_key;
$this->currencyCode = 'PLN';
// TODO: from configuration
$this->orderType = self::ORDER_TYPE_VIRTUAL;
\OpenPayU_Configuration::setEnvironment($this->environment);
\OpenPayU_Configuration::setMerchantPosId($this->merchantPosId);
\OpenPayU_Configuration::setPosAuthKey($this->posAuthKey);
\OpenPayU_Configuration::setClientId($this->clientId);
\OpenPayU_Configuration::setClientSecret($this->clientSecret);
\OpenPayU_Configuration::setSignatureKey($this->signatureKey);
$this->authUrl = \OpenPayU_Configuration::$authUrl;
$this->summaryUrl = \OpenPayU_Configuration::$summaryUrl;
$this->notifyUrl = $router->generate('webultdPayuPaymentBundle_status', array(), true);
$this->cancelUrl = $router->generate('webultdPayuPaymentBundle_cancel', array(), true);
$this->completeUrl = $router->generate('webultdPayuPaymentBundle_success', array(), true);
}
示例4: getEntityUrl
/**
* Get url for entity
*
* @param object $entity
* @param $item \Oro\Bundle\SearchBundle\Query\Result\Item
* @return string
*/
protected function getEntityUrl($entity, $item)
{
$name = $item->getEntityName();
$entityMeta = $this->em->getClassMetadata($name);
$identifierField = $entityMeta->getSingleIdentifierFieldName($entityMeta);
if ($this->mapper->getEntityMapParameter($name, 'route')) {
$routeParameters = $this->mapper->getEntityMapParameter($name, 'route');
$routeData = array();
if ($this->isParametersDefined($routeParameters)) {
/**
* NOTE: possible to generate url without entity object if only identifier field needed
*/
$idKey = array_search($identifierField, $routeParameters['parameters']);
$needToHaveEntity = $idKey === false || count($routeParameters['parameters']) > 1;
if (!$entity && $needToHaveEntity) {
$entity = $this->em->getRepository($name)->find($item->getRecordId());
}
foreach ($routeParameters['parameters'] as $parameter => $field) {
if ($entity) {
$routeData[$parameter] = $this->mapper->getFieldValue($entity, $field);
} else {
$routeData[$parameter] = $item->getRecordId();
}
}
}
return $this->router->generate($routeParameters['name'], $routeData, true);
}
return '';
}
示例5: __construct
public function __construct(Request $request, Router $router)
{
parent::__construct();
$this->setCurrentUri($request->getRequestUri());
$this->addChild('Song Library', $router->generate('song'));
$this->addChild('Add Song to Library', $router->generate('song_create'));
}
示例6: onKernelRequest
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
// don't redirect in dev
if ($this->isDebug) {
return;
}
$request = $event->getRequest();
$locale = $request->attributes->get('_locale');
// nothing to do here, not a URL that has to do with _locale route param
if (null === $locale) {
return;
}
// locale exists and is enabled, nothing to do here - return;
if ($this->manager->isLocaleEnabled($locale)) {
return;
}
$route = $request->attributes->get('_route');
// no route found, nothing to do here - return; and let the 404 handler do its job
if (null === $route) {
return;
}
$params = array_replace_recursive($request->attributes->get('_route_params', []), ['_locale' => $this->usePreferredLocale ? $this->manager->getPreferredLocale() : $this->manager->getDefaultLocale()]);
// generate a url for the same route with the same params, but with the default locale
$url = $this->router->generate($route, $params, UrlGeneratorInterface::ABSOLUTE_URL);
// append query string if any
$qs = $request->getQueryString();
if ($qs) {
$url = $url . '?' . $qs;
}
$response = new RedirectResponse($url, Response::HTTP_FOUND);
$event->setResponse($response);
}
示例7: postGif
public function postGif(Gif $gif)
{
$gifUrl = $this->router->generate('gif', ['permalink' => $gif->getPermalink()], true);
$gifUrl = Util::fixSymfonyGeneratedURLs($gifUrl);
$tweetContent = $gif->generateTweet($gifUrl);
return $this->postTweet($tweetContent);
}
示例8: process
public function process($data)
{
$mergedData = array_merge($this->defaults, $data);
// generating urls
if (isset($mergedData['url']) && $mergedData['url'] && strpos($mergedData['url'], '/') === false) {
$url = $this->router->generate($mergedData['url'], array(), true);
$mergedData['url'] = $url;
}
if (isset($mergedData['urlc']) && $mergedData['urlc'] && strpos($mergedData['urlc'], '/') === false) {
$urlc = $this->router->generate($mergedData['urlc'], array(), true);
$mergedData['urlc'] = $urlc;
}
$form = $this->form;
$form->bind($mergedData);
if (!$form->isValid()) {
$errors = array();
foreach ($form->getErrors() as $error) {
/* @var \Symfony\Component\Form\FormError $error */
$errors[] = $error->getMessageTemplate();
}
$logger = $this->logger;
$logger->err('Params: ' . json_encode($mergedData));
$logger->err('Errors: ' . json_encode($errors));
throw new \InvalidArgumentException('Invalid action parameters. Check profiler log information for more details');
}
return $form;
}
示例9: doWebPayment
/**
* @see : 3.1.1 PAYLINE-GUIDE-Descriptif des appels webservices.
* @param Order $order
* @return RedirectResponse
* @throws \Exception
*/
public function doWebPayment(Order $order)
{
/** @var Customer $subscriber */
$customer = $order->getCustomer();
$array['version'] = self::VERSION;
$array['returnURL'] = $this->frontRouter->generate('order.placed', ['order_id' => $order->getId()], true);
$array['cancelURL'] = $this->frontRouter->generate('order.failed', ['order_id' => $order->getId(), 'message' => 'payline'], true);
$array['notificationURL'] = $this->paylineRouter->generate('payline_notify', ['orderId' => $order->getId()], true);
$amount = (double) $order->getTotalAmount() * 100;
$currency = CurrencyNumericCodeQuery::create()->findPk($order->getCurrency()->getCode())->getNumericCode();
$array['payment']['amount'] = $amount;
$array['payment']['currency'] = $currency;
$array['payment']['action'] = '100';
$array['payment']['mode'] = 'CPT';
$array['payment']['contractNumber'] = $this->config->getContractNumber();
$array['order']['ref'] = $order->getRef();
$array['order']['amount'] = $amount;
$array['order']['currency'] = $currency;
$array['order']['date'] = $order->getUpdatedAt()->format('d/m/Y H:m');
$array['buyer']['lastName'] = $customer->getLastName();
$array['buyer']['firstName'] = $customer->getFirstName();
$array['buyer']['email'] = $customer->getEmail();
$array['securityMode'] = 'SSL';
$response = $this->payline->doWebPayment($array);
$code = $response['result']['code'];
if ($code !== '00000') {
$message = isset($response['result']['longMessage']) ? $response['result']['longMessage'] : 'Error undefined';
$this->logger->error($message);
throw new \Exception($message);
}
return new RedirectResponse($response['redirectURL']);
}
示例10: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
return;
}
$request = $event->getRequest();
$fc_form = $this->form_service->guessFcForm($request);
if (!$fc_form instanceof FcForm) {
return;
}
if ($fc_form->getAction()) {
return;
}
/** @var FormInterface $form */
$form = $this->form_service->create($fc_form);
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
$this->form_service->clear($fc_form, array('template' => $data['_template'], 'data' => $this->form_service->initData($data)));
if ($fc_form->getIsAjax()) {
return;
}
if ($fc_form->getMessage()) {
$message = $fc_form->getMessage();
} else {
$message = $this->translator->trans('fc.message.form.is_valid', array(), 'FenrizbesFormConstructorBundle');
}
// TODO: Связывать сообщение с конкретной формой и подчищать старые
$this->session->getFlashBag()->add('fc_form.success', $message);
$response = new RedirectResponse($this->router->generate($request->get('_route'), $request->get('_route_params')));
$event->setResponse($response);
}
}
示例11: Item
function it_should_create_translations_tools_menu(MenuEvent $menuEvent, Router $router)
{
$menuItem = new Item();
$menuEvent->getMenu()->willReturn($menuItem);
$router->generate('some_admin_route', array('locale' => 'en', 'element' => 'element'), UrlGeneratorInterface::ABSOLUTE_PATH)->willReturn('/admin/en/list/element');
$router->generate('some_admin_route', array('locale' => 'pl', 'element' => 'element'), UrlGeneratorInterface::ABSOLUTE_PATH)->willReturn('/admin/pl/list/element');
$router->generate('some_admin_route', array('locale' => 'de', 'element' => 'element'), UrlGeneratorInterface::ABSOLUTE_PATH)->willReturn('/admin/de/list/element');
$this->createTranslationLocaleMenu($menuEvent);
$rootItem = $menuItem->getChildren();
$translationLocale = $rootItem['translation-locale'];
expect($translationLocale->getLabel())->toBe('Menu label');
expect($translationLocale->getOption('attr'))->toHaveOption('id', 'translatable-switcher');
/** @var \FSi\Bundle\AdminBundle\Menu\Item\RoutableItem[] $subItems */
$subItems = $translationLocale->getChildren();
$localePl = $subItems['translation-locale.pl'];
$localeEn = $subItems['translation-locale.en'];
$localeDe = $subItems['translation-locale.de'];
expect($localePl->getLabel())->toBe('Polish');
expect($localePl->getRoute())->toBe('admin_translatable_list');
expect($localePl->getRouteParameters())->toBe(array('element' => 'event', 'locale' => 'pl', 'param1' => 'val1', 'redirect_uri' => '/admin/pl/list/element?param=value'));
expect($translationLocale->getOption('attr'))->toNotHaveOption('class', 'active');
expect($localeEn->getLabel())->toBe('English');
expect($localeEn->getRoute())->toBe('admin_translatable_list');
expect($localeEn->getRouteParameters())->toBe(array('element' => 'event', 'locale' => 'en', 'param1' => 'val1', 'redirect_uri' => '/admin/en/list/element?param=value'));
expect($translationLocale->getOption('attr'))->toNotHaveOption('class', 'active');
expect($localeDe->getLabel())->toBe('German');
expect($localeDe->getRoute())->toBe('admin_translatable_list');
expect($localeDe->getRouteParameters())->toBe(array('element' => 'event', 'locale' => 'de', 'param1' => 'val1', 'redirect_uri' => '/admin/de/list/element?param=value'));
expect($translationLocale->getOption('attr'))->toNotHaveOption('class', 'active');
}
示例12: onKernelRequest
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
$host = $request->getHost();
$baseHost = $this->baseHost;
$subdomain = str_replace('.' . $baseHost, '', $host);
//Check subDomain
$this->checkOldDomains($subdomain);
//Fix logout bug
$str = $baseHost . "/login";
if ($host != $baseHost && strstr($request->getUri(), $str, true)) {
$event->setResponse(new RedirectResponse($this->router->generate('buddy_system_user_homepage_index')));
}
//Fix dashboard error
if ($this->security_context->getToken() && $this->security_context->isGranted('IS_AUTHENTICATED_REMEMBERED') && $request->get('_route') == 'buddy_system_user_homepage_index') {
$this->checkSectionAccess();
$this->activityManager->setUser($this->security_context);
$this->activityManager->login();
if ($this->security_context->isGranted('ROLE_ADMIN') || $this->security_context->isGranted('ROLE_SUPER_ADMIN')) {
$event->setResponse(new RedirectResponse($this->router->generate('buddy_system_sadmin_homepage')));
} else {
if ($this->security_context->isGranted('ROLE_BUDDYCOORDINATOR')) {
$event->setResponse(new RedirectResponse($this->router->generate('buddy_system_admin_homepage')));
} else {
$event->setResponse(new RedirectResponse($this->router->generate('buddy_system_members_homepage')));
}
}
}
if ($host == $baseHost) {
if ($request->get('_route') != null && $request->get('_route') != "buddy_system_choose" && $request->get('_route') != "buddy_system_front_change_language_ajax") {
$event->setResponse(new RedirectResponse($this->router->generate('buddy_system_choose')));
}
} else {
//Redirection when /en or /fr at the end
$url = $request->getUri();
if (substr($url, -3) == "/fr" || substr($url, -3) == "/en") {
$event->setResponse(new RedirectResponse(substr($url, 0, strlen($url) - 3)));
}
//Add Section to local
if (!$this->sectionManager->getCurrentSection()) {
/** @var Section $section */
$section = $this->em->getRepository('BuddySystemMainBundle:Section')->findOneBy(array('subdomain' => $subdomain));
//Fix error on www
if (!$section && $subdomain == "www") {
header('Location: http://buddysystem.eu');
}
if (!$section) {
throw new NotFoundHttpException(sprintf('Cannot find section for host "%s", subdomain "%s"', $host, $subdomain));
}
if (!array_key_exists('section', $this->twig->getGlobals())) {
$this->twig->addGlobal('section', $section);
}
$this->sectionManager->setCurrentSection($section);
}
}
if ($this->security_context->getToken() && $this->security_context->getToken()->getUser() && $this->sectionManager->getCurrentSection()) {
$this->checkSectionAccess();
}
}
示例13: __construct
public function __construct(Request $request, Router $router)
{
parent::__construct();
$this->setCurrentUri($request->getRequestUri());
$this->addChild('Overview', $router->generate('dashboard'));
$this->addChild('Calendar', $router->generate('dashboard_calendar'));
$this->addChild('Other', 'http://www.stormid.com');
}
示例14: testIndexAction
public function testIndexAction()
{
$this->adminAuth();
$uri = $this->router->generate('rx_admin_pas_interfaces_file_index');
$crawler = $this->client->request('GET', $uri);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode(), 'Status code of "admin-pas-interfaces" must be 200.');
}
示例15: renderDeviceRoom
public function renderDeviceRoom(DeviceInterface $device)
{
$rooms = explode(',', $device->getAttribute('room')->getValue());
foreach ($rooms as &$room) {
$room = '<a href="' . $this->router->generate('frontend.default.room', array('name' => $room)) . '">' . $room . '</a>';
}
return implode(', ', $rooms);
}