Uri クラス
Uri クラスは URI を対話的に扱うのを可能にします。
base($include_index = true)
base メソッドはベース URL を返します。なお、 $include_index を false にセットした場合は、インデックスファイル index_file 名を除去して、
その URL を返します。
次の点に留意してください。: もし app/config/config.php で index_file がセットされていない場合は $include_index 変数は無視されます。
静的 |
はい |
パラメタ |
パラメータ |
初期値 |
説明 |
$include_index |
true
|
返り値の url に対してインデックスを付加するかどうかを決めます。 |
|
返り値 |
文字列, オプションとしてインデックスファイル名が付加されることがあるベースurlを返します。 |
例 |
echo Uri::base();
// http://localhost/index.php
echo Uri::base(false);
// http://localhost/
|
create($uri = null, $variables = array(), $get_variables = array(), $secure = null)
create メソッドは、 URI を加えた URL を生成することが出来ます。その URL にはベース URL を含みます。
静的 |
はい |
パラメタ |
パラメータ |
初期値 |
説明 |
$uri |
null
|
URL |
$variables |
array()
|
URL のための各種変数 |
$get_variables |
array()
|
URL に付加されるクエリー文字列。その値とキーは $variables 配列から得られた変数を
利用することが出来ます。 |
$secure |
null
|
生成される URL は、本項が false の場合は http, true の場合は https となります。 |
|
返り値 |
文字列 |
例 |
echo Uri::create('controller/method');
// http://localhost/controller/method が返ります。
echo Uri::create('controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'));
// http://localhost/controller/thing?what=more が返ります。
echo Uri::create('http://www.example.org/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'));
// http://www.example.org/thing?what=more が返ります。
echo Uri::create('http://www.example.org/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'), true);
// https://www.example.org/thing?what=more が返ります。
|
current()
current メソッドを用いると、現在の URL を取得出来ます。URL には HMVC パターン内部で定義されているベース URL が含まれます。
静的 |
はい |
パラメタ |
無し |
返り値 |
文字列 |
例 |
// URL例: http://localhost/module/controller/method
echo Uri::current(); // http://localhost/module/controller/method が返ります。
|
main()
main メソッドでベース URL を含む現在の URL を取得することが出来ます。
静的 |
はい |
パラメタ |
無し |
返り値 |
文字列 |
例 |
// URLの例: http://localhost/controller/method
echo Uri::main(); // returns http://localhost/controller/method
|
segment($segment, $default = null)
segment メソッドを用いると、取得したい特定の url セグメントを得ることができます。そのセグメントが存在しない場合は、 false が返されます。
静的 |
はい |
パラメタ |
パラメータ |
初期値 |
説明 |
$segment |
必須 |
セグメント番号 |
$default |
null
|
デフォルト?(The default?) |
|
返り値 |
文字列 |
例 |
// URLの例: http://localhost/controller/method/param1/param2
echo Uri::segment(3); // param1 が返ります。
|
segments()
segments メソッドによって、現在の URI セグメント全てを配列で取得することが出来ます。
静的 |
はい |
パラメタ |
無し |
返り値 |
配列 |
例 |
// URL例: http://localhost/controller/method
echo Uri::segments(); // array(0 => 'controller', 1 => 'method')が返ります。
|
segment_replace($url)
The segment_replace method allows you to replace wildcards in a given url by the current URI segment in that position.
静的 |
はい |
Parameters |
Param |
Default |
Description |
$url |
Required |
The url containing wildcards. A wildcard is defined by a * character. |
|
Returns |
string |
Throws |
OutOfBoundsException, if a wildcard is at a segment location for which no value exists. |
Example |
// Example: Current URL = http://localhost/one/two, with segments 'one' and 'two'
// returns http://localhost/one/two/three
echo Uri::segment_replace('http://localhost/*/*/three');
// throws an exception, as there is no third segment available
echo Uri::segment_replace('http://localhost/this/that/*/other');
|
to_assoc($start = 1)
to_assoc メソッドはセグメントが偶数の場合、それを配列化して連想配列にします。奇数の場合は、最後のキーの値は null
を返します。
静的 |
はい |
Parameters |
Param |
Default |
Description |
$start |
1
|
The segment number to start with. This allows you to strip leading segments. |
|
Returns |
array |
例 |
// Uri が /welcome/index/page/4 の場合
$arr = Uri::to_assoc();
/*
結果:
array(
'welcome' => 'index',
'page' => 4,
);
*/
// Uri が /welcome の場合
$arr = Uri::to_assoc();
/*
Result:
array(
'welcome' => null,
);
*/
|
string()
string メソッドを用いると、現在の URI を取得出来ます。
静的 |
はい |
パラメタ |
無し |
返り値 |
文字列 |
例 |
// URL例: http://localhost/controller/method
echo Uri::string(); // controller/method が返ります。
|