当前位置: 首页>>代码示例>>PHP>>正文


PHP UrlGenerator::generate方法代码示例

本文整理汇总了PHP中Symfony\Component\Routing\Generator\UrlGenerator::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlGenerator::generate方法的具体用法?PHP UrlGenerator::generate怎么用?PHP UrlGenerator::generate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Routing\Generator\UrlGenerator的用法示例。


在下文中一共展示了UrlGenerator::generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAbsoluteSecureUrlWithNonStandardPort

 public function testAbsoluteSecureUrlWithNonStandardPort()
 {
     $this->routeCollection->add('test', new Route('/testing'));
     $this->generator->setContext(array('base_url' => '/app.php', 'method' => 'GET', 'host' => 'localhost', 'port' => 8080, 'is_secure' => true));
     $url = $this->generator->generate('test', array(), true);
     $this->assertEquals('https://localhost:8080/app.php/testing', $url);
 }
开发者ID:rooster,项目名称:symfony,代码行数:7,代码来源:UrlGeneratorTest.php

示例2: getRouteUrl

 protected function getRouteUrl($name)
 {
     if (!isset($this->urlGenerator)) {
         throw new \Exception("URLGenerator was not set");
     }
     return $this->urlGenerator->generate($name);
 }
开发者ID:Dolondro,项目名称:rargh,代码行数:7,代码来源:AbstractController.php

示例3: urlAction

 /**
  * @Route("/url/{route}", bind="url", values={"route"=null})
  */
 public function urlAction($route)
 {
     if (null === $route) {
         $route = 'hello_name';
     }
     return $this->urlGenerator->generate($route, array('name' => 'urs'), UrlGeneratorInterface::ABSOLUTE_URL);
 }
开发者ID:saxulum,项目名称:saxulum-route-controller-provider,代码行数:10,代码来源:Test2Controller.php

示例4: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof NotInstalledException) {
         $response = new RedirectResponse($this->urlGenerator->generate('simplr_install_welcome'));
         $event->setResponse($response);
         return;
     }
 }
开发者ID:cleentfaar,项目名称:simplr-core,代码行数:12,代码来源:ExceptionListener.php

示例5: generate

 public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
 {
     if ($this->locale !== null && !isset($parameters[RouteAttribute::LOCALE])) {
         $parameters[RouteAttribute::LOCALE] = $this->locale;
     }
     return parent::generate($name, $parameters, $referenceType);
 }
开发者ID:blendsdk,项目名称:blendengine,代码行数:7,代码来源:UrlGenerator.php

示例6: generate

 /**
  * {@inheritdoc}
  */
 public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
 {
     // determine the most suitable locale to use for route generation
     $currentLocale = $this->context->getParameter('_locale');
     if (isset($parameters['_locale'])) {
         $locale = $parameters['_locale'];
     } else {
         if ($currentLocale) {
             $locale = $currentLocale;
         } else {
             $locale = 'en';
         }
     }
     try {
         if (false !== ($pos = strpos($name, I18nControllerCollection::ROUTING_PREFIX))) {
             $name = substr($name, $pos + strlen(I18nControllerCollection::ROUTING_PREFIX));
         }
         $url = parent::generate($locale . I18nControllerCollection::ROUTING_PREFIX . $name, $parameters, $referenceType);
         return $url;
     } catch (RouteNotFoundException $ex) {
         // fallback to default behavior
     }
     // use the default behavior if no localized route exists
     return parent::generate($name, $parameters, $referenceType);
 }
开发者ID:raphaelvigee,项目名称:I18nRoutingServiceProvider,代码行数:28,代码来源:I18nUrlGenerator.php

示例7: testListBucket

 public function testListBucket()
 {
     $this->authorize();
     $listUrl = $this->urlGenerator->generate('list', ['bucket' => 'foo']);
     $listBuckets = new Result(['Buckets' => [['Name' => 'foo', 'CreationDate' => '2014-08-01T14:00:00.000Z'], ['Name' => 'bar', 'CreationDate' => '2014-07-31T20:30:40.000Z']]]);
     $listObjects = new Result(['Contents' => [['Key' => 'baz', 'ETag' => '"' . md5('baz') . '"', 'LastModified' => '2014-09-10T11:12:13.000Z', 'Size' => 1024], ['Key' => 'qux', 'ETag' => '"' . md5('qux') . '"', 'LastModified' => '2014-09-11T21:22:23.000Z', 'Size' => 2048], ['Key' => 'quxx', 'ETag' => '"' . md5('quxx') . '"', 'LastModified' => '2014-09-12T00:00:00.000Z', 'Size' => 512]], 'IsTruncated' => false]);
     $this->s3ClientMock->expects($this->once())->method('listBuckets')->willReturn($listBuckets);
     $this->s3ClientMock->expects($this->once())->method('listObjects')->willReturn($listObjects);
     $crawler = $this->client->request('GET', $listUrl);
     $this->assertTrue($this->client->getResponse()->isOk());
     // buckets
     $list = $crawler->filter('#list-bucket li');
     $active = $list->filter('.active');
     $this->assertCount(count($listBuckets['Buckets']), $list);
     $this->assertCount(1, $active);
     $this->assertEquals($list->eq(0), $active);
     $urlGenerator = $this->urlGenerator;
     $list->each(function (Crawler $bucket, $index) use($urlGenerator, $listBuckets) {
         $link = $bucket->filter('a');
         $expectedName = $listBuckets['Buckets'][$index]['Name'];
         $this->assertEquals($expectedName, $link->text());
         $this->assertEquals($urlGenerator->generate('list', ['bucket' => $expectedName]), $link->attr('href'));
     });
     // objects
     $list = $crawler->filter('#list-object tbody tr');
     $this->assertCount(count($listObjects['Contents']), $list);
     $list->each(function (Crawler $object, $index) use($listObjects) {
         $link = $object->filter('td')->eq(0)->filter('a');
         $expectedKey = $listObjects['Contents'][$index]['Key'];
         $this->assertEquals($expectedKey, $link->text());
         $this->assertEquals('http://foo.s3.amazonaws.com/' . $expectedKey, $link->attr('href'));
         $this->assertEquals($listObjects['Contents'][$index]['Size'], $object->filter('td')->eq(1)->text());
     });
 }
开发者ID:ossinkine,项目名称:amazon-s3-client,代码行数:34,代码来源:ApplicationTest.php

示例8: url

 /**
  * @param $route_alias
  * @param $args
  * @return string
  */
 public function url($route_alias, $args = array())
 {
     $routes = $this->router->getRoutes();
     $context = new RequestContext(self::getAssetDirectory());
     $generator = new UrlGenerator($routes, $context);
     return $generator->generate($route_alias, $args);
 }
开发者ID:joussin,项目名称:framework,代码行数:12,代码来源:HelperService.php

示例9: generate

 /**
  * {@inheritdoc}
  */
 public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
 {
     $url = parent::generate($name, $parameters, $referenceType);
     if (substr($url, -6) == '/index') {
         $url = rtrim($url, "index");
     }
     return $url;
 }
开发者ID:Opifer,项目名称:Cms,代码行数:11,代码来源:UrlGenerator.php

示例10: generate

 public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
 {
     try {
         return parent::generate($name, $parameters, $referenceType);
     } catch (RouteNotFoundException $e) {
         return $this->generator->generate($name, $parameters, $referenceType);
     }
 }
开发者ID:elfet,项目名称:silicone,代码行数:8,代码来源:UrlGeneratorDecorator.php

示例11: generate

 public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
 {
     if (null === $this->namespace || !$referenceType) {
         return parent::generate($name, $parameters, $referenceType);
     } else {
         return $this->getBaseUrl() . parent::generate($name, $parameters, false);
     }
 }
开发者ID:pitpit,项目名称:faceboo,代码行数:8,代码来源:UrlGenerator.php

示例12: generate

 public function generate($name, array $parameters = array(), $absolute = false)
 {
     if (null === $this->namespace || !$absolute) {
         return parent::generate($name, $parameters, $absolute);
     } else {
         return $this->getBaseUrl() . parent::generate($name, $parameters, false);
     }
 }
开发者ID:emgiezet,项目名称:faceboo,代码行数:8,代码来源:UrlGenerator.php

示例13: route

 /**
  * Get the URL to a named route.
  *
  * @param  string  $name
  * @param  array   $parameters
  * @param  bool    $absolute
  * @return string
  */
 public function route($name, $parameters = array(), $absolute = true)
 {
     $route = $this->routes->get($name);
     if (isset($route) and $this->usingQuickParameters($parameters)) {
         $parameters = $this->buildParameterList($route, $parameters);
     }
     return $this->generator->generate($name, $parameters, $absolute);
 }
开发者ID:defra91,项目名称:levecchiecredenze.it,代码行数:16,代码来源:UrlGenerator.php

示例14: deleteAction

 /**
  * @Route("/delete/{id}", bind="example_delete", asserts={"name"="\d+"})
  * @param $id
  * @return RedirectResponse
  * @throws NotFoundHttpException
  */
 public function deleteAction($id)
 {
     $example = $this->doctrine->getManager()->getRepository(get_class(new Example()))->find($id);
     if (is_null($example)) {
         throw new NotFoundHttpException("Can't find example with id {$id}");
     }
     $this->doctrine->getManager()->remove($example);
     $this->doctrine->getManager()->flush();
     return new RedirectResponse($this->urlGenerator->generate('example_list'), 302);
 }
开发者ID:saxulum,项目名称:saxulum,代码行数:16,代码来源:ExampleController.php

示例15: path

 public function path($routeName, $parameters = array())
 {
     /** @var Route $route */
     $route = $this->routes->get($routeName);
     if ($route) {
         $context = new RequestContext();
         $generator = new UrlGenerator($this->routes, $context);
         return $generator->generate($routeName, $parameters);
     }
     return '';
 }
开发者ID:zyncro,项目名称:framework,代码行数:11,代码来源:TwigPath.php


注:本文中的Symfony\Component\Routing\Generator\UrlGenerator::generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。