/**
  * Returns the URL from a page object, including current parameter values.
  * @return string
  */
 protected function makeLocaleUrlFromPage($locale)
 {
     $page = $this->getPage();
     /*
      * Static Page
      */
     if (isset($page->apiBag['staticPage'])) {
         $staticPage = $page->apiBag['staticPage'];
         $staticPage->rewriteTranslatablePageUrl($locale);
         $localeUrl = array_get($staticPage->attributes, 'viewBag.url');
     } else {
         $page->rewriteTranslatablePageUrl($locale);
         $router = new RainRouter();
         $params = $this->getRouter()->getParameters();
         $localeUrl = $router->urlFromPattern($page->url, $params);
     }
     return $localeUrl;
 }
Example #2
0
 public function index_onOpenTemplate()
 {
     $this->validateRequestTheme();
     $type = Request::input('type');
     $template = $this->loadTemplate($type, Request::input('path'));
     $widget = $this->makeTemplateFormWidget($type, $template);
     $this->vars['templatePath'] = Request::input('path');
     if ($type == 'page') {
         $router = new RainRouter();
         $this->vars['pageUrl'] = $router->urlFromPattern($template->url);
     }
     return ['tabTitle' => $this->getTabTitle($type, $template), 'tab' => $this->makePartial('form_page', ['form' => $widget, 'templateType' => $type, 'templateTheme' => $this->theme->getDirName(), 'templateMtime' => $template->mtime])];
 }
Example #3
0
 /**
  * Autoloads the URL map only allowing a single execution.
  * @return array Returns the URL map.
  */
 protected function getRouterObject()
 {
     if (self::$routerObj !== null) {
         return self::$routerObj;
     }
     /*
      * Load up each route rule
      */
     $router = new RainRouter();
     foreach ($this->getUrlMap() as $pageInfo) {
         $router->route($pageInfo['file'], $pageInfo['pattern']);
     }
     /*
      * Sort all the rules
      */
     $router->sortRules();
     return self::$routerObj = $router;
 }
Example #4
0
 public function testUrl()
 {
     $params = [];
     $router = new Router();
     // Set up some dummy rules
     $router->route('authorDetails', '/authors/:author_id?/:details?');
     $router->route('blogPost', 'blog/post');
     $router->route('userProfile', 'profile/:username');
     $router->route('jobRequest', 'job/:type?request/:id');
     $router->route('productPage', '/product/:category?/:id');
     $router->route('portfolioPage', '/portfolio/:year?noYear/:category?noCategory/:budget?noBudget');
     $result = $router->url('blogPost');
     $this->assertEquals('/blog/post', $result);
     $result = $router->url('authorDetails');
     $this->assertEquals('/authors', $result);
     $result = $router->url('authorDetails', ['author_id' => 20]);
     $this->assertEquals('/authors/20', $result);
     $result = $router->url('authorDetails', ['details' => 'history']);
     $this->assertEquals('/authors/default/history', $result);
     $result = $router->url('authorDetails', ['author_id' => 'default']);
     $this->assertEquals('/authors/default', $result);
     $result = $router->url('userProfile', ['username' => 'shaq']);
     $this->assertEquals('/profile/shaq', $result);
     $result = $router->url('jobRequest', ['id' => '9']);
     $this->assertEquals('/job/request/9', $result);
     $result = $router->url('jobRequest');
     $this->assertEquals('/job/request/default', $result);
     $result = $router->url('productPage', ['id' => '7']);
     $this->assertEquals('/product/default/7', $result);
     $result = $router->url('productPage', ['id' => '7', 'category' => 'helmets']);
     $this->assertEquals('/product/helmets/7', $result);
     $result = $router->url('portfolioPage');
     $this->assertEquals('/portfolio', $result);
     $result = $router->url('portfolioPage', ['year' => '2020']);
     $this->assertEquals('/portfolio/2020', $result);
     $result = $router->url('portfolioPage', ['category' => 'shoes']);
     $this->assertEquals('/portfolio/noYear/shoes', $result);
     $result = $router->url('portfolioPage', ['category' => null, 'budget' => '50000-above']);
     $this->assertEquals('/portfolio/noYear/noCategory/50000-above', $result);
     $result = $router->url('portfolioPage', ['year' => false, 'category' => null, 'budget' => 0]);
     $this->assertEquals('/portfolio/noYear/noCategory/0', $result);
     $result = $router->url('portfolioPage', ['budget' => 0]);
     $this->assertEquals('/portfolio/noYear/noCategory/0', $result);
     $result = $router->url('portfolioPage', ['year' => '2020', 'category' => 'noCategory']);
     $this->assertEquals('/portfolio/2020', $result);
     $result = $router->url('portfolioPage', ['year' => 'default', 'category' => 'noCategory', 'budget' => '200-500']);
     $this->assertEquals('/portfolio/default/noCategory/200-500', $result);
 }
Example #5
0
 public function testUrl()
 {
     $params = array();
     $router = new Router();
     // Set up some dummy rules
     $router->route('authorDetails', '/authors/:author_id?/:details?');
     $router->route('blogPost', 'blog/post');
     $router->route('userProfile', 'profile/:username');
     $router->route('jobRequest', 'job/:type?request/:id');
     $router->route('productPage', '/product/:category?/:id');
     $result = $router->url('blogPost');
     $this->assertEquals('/blog/post', $result);
     $result = $router->url('authorDetails');
     $this->assertEquals('/authors', $result);
     $result = $router->url('authorDetails', array('author_id' => 20));
     $this->assertEquals('/authors/20', $result);
     $result = $router->url('authorDetails', array('details' => 'history'));
     $this->assertEquals('/authors/default/history', $result);
     $result = $router->url('userProfile', array('username' => 'shaq'));
     $this->assertEquals('/profile/shaq', $result);
     $result = $router->url('jobRequest', array('id' => '9'));
     $this->assertEquals('/job/request/9', $result);
     $result = $router->url('jobRequest');
     $this->assertEquals('/job/request/default', $result);
     $result = $router->url('productPage', array('id' => '7'));
     $this->assertEquals('/product/default/7', $result);
     $result = $router->url('productPage', array('id' => '7', 'category' => 'helmets'));
     $this->assertEquals('/product/helmets/7', $result);
 }