現在アクセスしているURLをスラッシュ区切りで配列に格納するクラスです。
ディレクトリによるコールするコントローラーやモデルの判別等にご使用ください。
function GetScript()
$this->script はディレクトリと、スクリプト名(index.phpやindex.htmlなど)を返します。
| アクセスURL | 取得される値 |
|---|---|
| http://ドメイン.com/direct/ | direct, index.php |
| http://ドメイン.com/direct/detail.php | direct, detail.php |
function GetUri()
$this->uri はディレクトリと、アクセスされたスクリプト名を返します。
| アクセスURL | 取得される値 |
|---|---|
| http://ドメイン.com/direct/ | direct |
| http://ドメイン.com/direct/detail.php | direct, detail.php |
function GetUriDir()
$this->dir は、スクリプト名を無視し、ディレクトリ名のみ返します。
| アクセスURL | 取得される値 |
|---|---|
| http://ドメイン.com/direct/ | direct |
| http://ドメイン.com/direct/detail.php | direct |
function GetPath()
$this->path は、 $this->dir 配列を / を語尾へ含めながら、文字列へ再変換します。
| アクセスURL | 取得される値 |
|---|---|
| http://ドメイン.com/direct/ | /direct/ |
| http://ドメイン.com/direct/detail.php | /direct/ |
| http://ドメイン.com/direct/detail/ | /direct/detail/ |
現在アクセスしているURLをスラッシュ区切りで配列に格納するクラス
class GetDir {
public $script;
public $uri;
public $dir = array();
public $path;
function GetDir() {
$this->GetScript();
$this->GetUri();
$this->GetUriDir();
$this->GetPath();
return;
}
function GetScript() {
$server = $_SERVER['SCRIPT_NAME'];
$this->script = array_values(array_filter(explode("/",$server)));
return;
}
function GetUri() {
$server = $_SERVER['REQUEST_URI'];
$this->uri = array_values(array_filter(explode("/",$server)));
return;
}
function GetUriDir() {
foreach($this->uri as $val) {
if(
preg_match("/\.php/",$val) ||
preg_match("/\.html/",$val) ||
preg_match("/\.htm/",$val)
) {
continue;
} else {
array_push($this->dir,$val);
}
}
return;
}
function GetPath() {
$this->path = "/";
foreach($this->dir as $val) {
$this->path .= $val . "/";
}
return;
}
}