本文整理汇总了PHP中Dispatcher::path方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::path方法的具体用法?PHP Dispatcher::path怎么用?PHP Dispatcher::path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setPathAndAction
/**
* リクエストされたURLをパースして、ClassとActionを決定
*
* @param string $APP_ROOT 現在のMinアプリの絶対ディレクトリパス
* @return void
*/
protected static function setPathAndAction($APP_ROOT)
{
# cssフォルダとjsフォルダのファイルはそのまま吐き出す
if (preg_match("!^/.*/(css|js)/.*!", $_SERVER['SCRIPT_NAME'], $m)) {
$filePath = $APP_ROOT . '/view' . $_SERVER['SCRIPT_NAME'];
if (file_exists($filePath)) {
$time = filemtime($filePath);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $time) . ' GMT');
if ($m[1] == 'css') {
header("Content-Type: text/css");
} elseif ($m[1] == 'js') {
header("Content-Type: text/javascript");
}
readfile($filePath);
} else {
header("HTTP/1.0 404 Not Found");
echo "404 CSS|JS Not Found";
}
exit;
}
# (/imgフォルダ外の)JPEG、PNG、GIF画像を吐き出す
if (preg_match("!^/(.*)\\.(jpeg|JPEG|jpg|JPG|png|PNG|gif|GIF)!", $_SERVER['SCRIPT_NAME'], $m)) {
$filePath = $APP_ROOT . '/var/images' . $_SERVER['SCRIPT_NAME'];
Console::log($filePath);
if (file_exists($filePath)) {
self::sendImage($filePath);
} else {
header("HTTP/1.0 404 Not Found");
echo "404 Image Not Found";
}
exit;
}
# 言語を選択
if (preg_match("!^/(en|fr)/(.*)!", $_SERVER['SCRIPT_NAME'], $m)) {
$SCRIPT_NAME = '/' . $m[2];
self::$lang = $m[1];
} else {
$SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
self::$lang = 'jp';
}
# '/' にmatch
if ($SCRIPT_NAME == '/') {
if (self::$trace) {
Console::log('Dispatcher:A');
Console::log($m);
}
self::$path = '/';
self::$class = 'IndexCtl';
self::$classFile = '/IndexCtl.php';
self::$action = 'index';
// action = function index()
return;
}
# '/abcd' にmatch
if (preg_match("|^/([^/]*)\$|", $SCRIPT_NAME, $m)) {
if (self::$trace) {
Console::log('Dispatcher:B');
Console::log($m);
}
self::$path = '/';
self::$class = 'IndexCtl';
self::$classFile = '/IndexCtl.php';
self::$action = $m[1];
// action = function abcd()
return;
}
# '/abcd/' にmatch (actionを省略)
if (preg_match("|^/([^/]*)/\$|", $SCRIPT_NAME, $m)) {
if (self::$trace) {
Console::log('Dispatcher:C');
Console::log($m);
}
self::$path = $SCRIPT_NAME;
// pass = /abcd/
self::$class = ucfirst($m[1]) . 'Ctl';
// class = class AbcdCtl
self::$classFile = self::$path . self::$class . '.php';
// file = /abcd/AbcdCtl.php
self::$action = 'index';
// action = function index()
return;
}
# '/abcd/efg'や'/abcd/efg/hij' にmatch
if (preg_match("|^/(.*)/([^/]*?[^/])\$|", $SCRIPT_NAME, $m)) {
if (self::$trace) {
Console::log('Dispatcher:D');
Console::log($m);
}
self::$path = '/' . $m[1] . '/';
// pass = /abcd/efg/
$tArray = explode('/', $m[1]);
//self::$class = array_pop($tArray).'Ctl'; // class = class efgCtl
foreach ($tArray as $key => $val) {
$tArray[$key] = ucfirst($val);
//.........这里部分代码省略.........
示例2: uri
protected function uri($segment = NULL)
{
$path = explode('/', Dispatcher::path());
array_shift($path);
if ($segment === NULL) {
// Return an array of the path
return $this->sanitize($path);
} elseif ($segment === TRUE) {
// Return an string of the path
return implode('/', $this->sanitize($path));
} else {
// Return just a segement of the path
return $this->sanitize($path[$segment]);
}
}