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


PHP Page::route方法代码示例

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


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

示例1: __construct

 /**
  * Create form for the given page.
  *
  * @param Page $page
  * @param null $name
  * @param null $form
  */
 public function __construct(Page $page, $name = null, $form = null)
 {
     parent::__construct();
     $this->page = $page->route();
     $header = $page->header();
     $this->rules = isset($header->rules) ? $header->rules : [];
     $this->header_data = isset($header->data) ? $header->data : [];
     if ($form) {
         $this->items = $form;
     } else {
         if (isset($header->form)) {
             $this->items = $header->form;
             // for backwards compatibility
         }
     }
     // Add form specific rules.
     if (!empty($this->items['rules']) && is_array($this->items['rules'])) {
         $this->rules += $this->items['rules'];
     }
     // Set form name if not set.
     if ($name && !is_int($name)) {
         $this->items['name'] = $name;
     } elseif (empty($this->items['name'])) {
         $this->items['name'] = $page->slug();
     }
     // Set form id if not set.
     if (empty($this->items['id'])) {
         $inflector = new Inflector();
         $this->items['id'] = $inflector->hyphenize($this->items['name']);
     }
     // Reset and initialize the form
     $this->reset();
 }
开发者ID:getgrav,项目名称:grav-plugin-form,代码行数:40,代码来源:form.php

示例2: addPage

 /**
  * Adds a page and assigns a route to it.
  *
  * @param Page   $page   Page to be added.
  * @param string $route  Optional route (uses route from the object if not set).
  */
 public function addPage(Page $page, $route = null)
 {
     if (!isset($this->instances[$page->path()])) {
         $this->instances[$page->path()] = $page;
     }
     $route = $page->route($route);
     if ($page->parent()) {
         $this->children[$page->parent()->path()][$page->path()] = array('slug' => $page->slug());
     }
     $this->routes[$route] = $page->path();
 }
开发者ID:alexslack,项目名称:faith-game,代码行数:17,代码来源:Pages.php

示例3: convertUrl

 /**
  * Converts links from absolute '/' or relative (../..) to a grav friendly format
  *
  * @param         $page         the current page to use as reference
  * @param  string $markdown_url the URL as it was written in the markdown
  *
  * @return string the more friendly formatted url
  */
 public static function convertUrl(Page $page, $markdown_url)
 {
     $grav = Grav::instance();
     $pages_dir = $grav['locator']->findResource('page://');
     $base_url = rtrim($grav['base_url'] . $grav['pages']->base(), '/');
     // if absolute and starts with a base_url move on
     if (pathinfo($markdown_url, PATHINFO_DIRNAME) == '.' && $page->url() == '/') {
         return '/' . $markdown_url;
         // no path to convert
     } elseif ($base_url != '' && Utils::startsWith($markdown_url, $base_url)) {
         return $markdown_url;
         // if contains only a fragment
     } elseif (Utils::startsWith($markdown_url, '#')) {
         return $markdown_url;
     } else {
         $target = null;
         // see if page is relative to this or absolute
         if (Utils::startsWith($markdown_url, '/')) {
             $normalized_url = Utils::normalizePath($base_url . $markdown_url);
             $normalized_path = Utils::normalizePath($pages_dir . $markdown_url);
         } else {
             $normalized_url = $base_url . Utils::normalizePath($page->route() . '/' . $markdown_url);
             $normalized_path = Utils::normalizePath($page->path() . '/' . $markdown_url);
         }
         // special check to see if path checking is required.
         $just_path = str_replace($normalized_url, '', $normalized_path);
         if ($just_path == $page->path()) {
             return $normalized_url;
         }
         $url_bits = parse_url($normalized_path);
         $full_path = $url_bits['path'];
         if (file_exists($full_path)) {
             // do nothing
         } elseif (file_exists(urldecode($full_path))) {
             $full_path = urldecode($full_path);
         } else {
             return $normalized_url;
         }
         $path_info = pathinfo($full_path);
         $page_path = $path_info['dirname'];
         $filename = '';
         if ($markdown_url == '..') {
             $page_path = $full_path;
         } else {
             // save the filename if a file is part of the path
             if (is_file($full_path)) {
                 if ($path_info['extension'] != 'md') {
                     $filename = '/' . $path_info['basename'];
                 }
             } else {
                 $page_path = $full_path;
             }
         }
         // get page instances and try to find one that fits
         $instances = $grav['pages']->instances();
         if (isset($instances[$page_path])) {
             $target = $instances[$page_path];
             $url_bits['path'] = $base_url . $target->route() . $filename;
             return Uri::buildUrl($url_bits);
         }
         return $normalized_url;
     }
 }
开发者ID:rdquintas,项目名称:Alphalink,代码行数:71,代码来源:Uri.php


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