本文整理汇总了PHP中Uri::segments方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::segments方法的具体用法?PHP Uri::segments怎么用?PHP Uri::segments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uri
的用法示例。
在下文中一共展示了Uri::segments方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Get menu
*
* @param string $category Category name
*/
public static function get($category = '')
{
// Get menu table
$menu = new Table('menu');
// Display view
View::factory('box/menu/views/frontend/index')->assign('items', $menu->select('[category="' . $category . '"]', 'all', null, array('id', 'name', 'link', 'target', 'order', 'category'), 'order', 'ASC'))->assign('uri', Uri::segments())->assign('defpage', Option::get('defaultpage'))->display();
}
示例2: get
/**
* Get slider
*
* @param string $category Category name
*/
public static function get($category = '')
{
if ($category == 'default') {
$category = '';
}
// Get slider table
$slider = new Table('slider');
// Display view
View::factory('slider/views/frontend/index')->assign('items', $slider->select('[category="' . $category . '"]', 'all', null, null, 'order', 'ASC'))->assign('uri', Uri::segments())->assign('defpage', Option::get('defaultpage'))->display();
}
示例3: before
public function before()
{
// Set template
$this->theme = \Theme::instance();
$this->theme->set_template($this->template);
// Load translation
\Lang::load('blog');
// Get current segments
$segments = \Uri::segments();
empty($segments) and $segments[0] = 'home';
$this->dataGlobal['segments'] = $segments;
// If ajax or content_only, set a theme with an empty layout
if (\Input::is_ajax()) {
return parent::before();
}
// Don't re-set Media if is an HMVC request
!\Request::is_hmvc() and $this->setMedia();
}
示例4: initialise
/**
* Init
*
* Initialise breadcrumb based on URI segments
*
* @access protected
* @return void
*/
protected static function initialise()
{
$home = \Config::get('breadcrumb.home', static::$home);
$use_lang = \Config::get('breadcrumb.use_lang', static::$use_lang);
static::set($home['name'], $home['link']);
$segments = \Uri::segments();
$link = '';
foreach ($segments as $segment) {
if (preg_match('/^([0-9])+$/', $segment) > 0 or $segment === 'index') {
continue;
}
$link .= '/' . $segment;
if ($use_lang === true) {
static::set(\Lang::get($segment), $link);
} else {
static::set(\Str::ucwords(str_replace('_', ' ', $segment)), $link);
}
}
}
示例5: _parsecustom
/**
* PARSE ROUTES
* This function matches any routes that may exist
* to determine if the class/method needs to be remapped.
**/
private static function _parsecustom()
{
$seg = Uri::segments();
// Are there any custom routes?
if (count(self::$_RTR) == 0) {
self::_set($seg);
return;
}
// Turn the segment array into an URI string
$uri = implode('/', $seg);
$num = count($seg);
// return if literal match is found.
if (isset(self::$_RTR[$uri])) {
self::_set(explode('/', self::$_RTR[$uri]));
return;
}
// Get the available wildcards from the library
$wc = Core::config('routing_wildcards');
if (!is_array($wc)) {
Core::error('ARRTYP', 'LIBTIT', array(__CLASS__, 'routing_wildcards'));
}
// Search through the segment array for wild-cards
foreach (self::$_RTR as $key => $val) {
// convert wild cards to regex
if (count($wc) > 0) {
foreach ($wc as $k => $v) {
$key = str_replace($k, $v, $key);
}
}
// check for regex matches
if (preg_match('#^' . $key . '$#', $uri)) {
// do we have a back-reference
if (strpos($val, '$') !== false && strpos($key, '(') !== false) {
$val = preg_replace('#^' . $key . '$#', $val, $uri);
}
self::_set(explode('/', $val));
return;
}
}
// there was no matching route follow default route
self::_set($seg);
}
示例6: before
public function before()
{
parent::before();
\Session::set("current_page", \Uri::string());
$segments = implode(\Uri::segments());
if (Auth::check() || $segments == 'userlogin') {
list($driver, $user_id) = Auth::get_user_id();
$this->current_user = Model_User::find($user_id);
} else {
if ($segments != 'userlogin') {
Session::set("lastpage", implode("/", \Uri::segments()));
}
$this->current_user = null;
Response::redirect('user/login');
}
if ($segments != 'userlogin') {
View::set_global('group_name', Auth_Group_SimpleGroup::instance()->get_name($this->current_user->group));
View::set_global('current_user', $this->current_user);
}
}
示例7: before
public function before()
{
$this->template = $this->newIntranet() ? "templates/layout" : "template";
\Session::set("current_page", \Uri::string());
$segments = implode(\Uri::segments());
if (\Auth::check() || $segments == 'userlogin') {
list($driver, $user_id) = \Auth::get_user_id();
$this->current_user = \Model_User::find($user_id);
} else {
if ($segments != 'userlogin') {
\Session::set("lastpage", implode("/", \Uri::segments()));
}
$this->current_user = null;
\Response::redirect('user/login');
}
if ($segments != 'userlogin') {
\View::set_global('group_name', \Auth_Group_SimpleGroup::instance()->get_name($this->current_user->group));
\View::set_global('current_user', $this->current_user);
}
parent::before();
// Remove when login implemented
}
示例8: match_trigger
/**
* Match configured triggers with current URI.
*/
private static function match_trigger($triggers)
{
// get uri segments
$current_uri = \Uri::segments();
// try to match a trigger with the current uri segments
foreach ($triggers as $trigger) {
// create array of this trigger
$trigger_uri = explode('/', $trigger);
// slice trigger array at the wildcard (*)
$pos = array_search('*', $trigger_uri);
if ($pos !== false) {
// slice arrays to equal size
$current_uri = array_slice($current_uri, 0, $pos);
$trigger_uri = array_slice($trigger_uri, 0, $pos);
}
// compare arrays
if ($trigger_uri == $current_uri) {
return true;
}
}
return false;
}
示例9: render_breadcrumbs
private function render_breadcrumbs()
{
$uri = \Uri::segments();
$base = \Config::get('petro.breadcrumb.base', 'Home');
$link = \Uri::base();
$sep = \Config::get('petro.breadcrumb.separator', '/');
$out = '<span class="breadcrumb">' . PHP_EOL;
$out .= '<a href="#">' . $base . '</a><span class="breadcrumb_sep">' . $sep . '</span>';
for ($i = 0; $i < count($uri) - 1; $i++) {
$link .= $uri[$i] . $sep;
$out .= '<a href="' . $link . '">' . $uri[$i] . '</a>';
$out .= '<span class="breadcrumb_sep">' . $sep . '</span>' . PHP_EOL;
}
$out .= '</span>' . PHP_EOL;
return $out;
}
示例10: pageLoader
/**
* Page loader
*
* @param boolean $return_data data
* @return array
*/
public static function pageLoader($return_data = true)
{
$requested_page = Pages::lowLoader(Uri::segments());
Pages::$requested_page = $requested_page;
return Pages::$pages->select('[slug="' . $requested_page . '"]', null);
}
示例11: __construct
/**
* Creates the new Request object by getting a new URI object, then parsing
* the uri with the Route class.
*
* Usage:
*
* $request = new Request('foo/bar');
*
* @param string the uri string
* @param bool whether or not to route the URI
* @param string request method
* @return void
*/
public function __construct($uri, $route = true, $method = null)
{
$this->uri = new \Uri($uri);
$this->method = $method;
logger(\Fuel::L_INFO, 'Creating a new Request with URI = "' . $uri . '"', __METHOD__);
// check if a module was requested
if (count($this->uri->segments()) and $module_path = \Module::exists($this->uri->get_segment(0))) {
// check if the module has routes
if (is_file($module_path .= 'config/routes.php')) {
$module = $this->uri->segments[0];
// load and add the module routes
$module_routes = \Fuel::load($module_path);
$prepped_routes = array();
foreach ($module_routes as $name => $_route) {
if ($name === '_root_') {
$name = $module;
} elseif (strpos($name, $module . '/') !== 0 and $name != $module and $name !== '_404_') {
$name = $module . '/' . $name;
}
$prepped_routes[$name] = $_route;
}
// update the loaded list of routes
\Router::add($prepped_routes, null, true);
}
}
$this->route = \Router::process($this, $route);
if (!$this->route) {
return;
}
$this->module = $this->route->module;
$this->controller = $this->route->controller;
$this->action = $this->route->action;
$this->method_params = $this->route->method_params;
$this->named_params = $this->route->named_params;
if ($this->route->module !== null) {
$this->add_path(\Module::exists($this->module));
}
}
示例12: filterRoute
/**
* map individual routes
*
* @return mixed[object|void]
*/
function filterRoute(Route $object)
{
//now we have everything in place, run any closures passed from the config
$object = $object->filter(Uri::segments(), null);
return $object;
}
示例13: params
/**
* Get uri parammeters
*
* <code>
* $params = Uri::params();
* </code>
*
* @return array
*/
public static function params()
{
//Init data array
$data = array();
// Get URI
$uri = Uri::segments();
// http://site.com/ and http://site.com/index.php same main home pages
if (!isset($uri[0])) {
$uri[0] = '';
}
// param1/param2
if ($uri[0] !== Uri::$default_component) {
if (isset($uri[1])) {
foreach ($uri as $part) {
$data[] = $part;
}
} else {
// default
$data[0] = $uri[0];
}
} else {
// This is good for box plugin Pages
// parent/child
if (isset($uri[2])) {
$data[0] = $uri[1];
$data[1] = $uri[2];
} else {
// default
$data[0] = $uri[1];
}
}
return $data;
}
示例14: getImagePath
/**
* Get the current base path, stopping at the given segment number
*/
protected function getImagePath($startSegment)
{
$segments = \Uri::segments();
$startSegment = min($startSegment, count($segments));
return implode('/', array_slice($segments, $startSegment)) . '.' . \Input::extension();
}