独自のテンプレート システムを備えた PHP フレームワークを作成しました。これは、フロントエンドで必要に応じて機能します。テンプレート システムは?url=($page)
、URL の の部分を使用して、ユーザーが要求するページを特定し、ファイルの内容を という名前で表示します($page)
。次に、htaccess を使用して URL を「きれいに」します。
ただし、フレームワークを拡張して、$_GET['url']
containsかどうかを識別し、含まれbackend
ている場合は、別の文字列の末尾にスラッシュがあるかどうかを確認します。たとえば、の値が$_GET['url']
isの場合、バックエンド フォルダー内からbackend/manage-gallery
ページを返すようにします。manage-gallery
ここに私が今持っているコードがあります。$_GET['url']
現在、値が backendの場合、ページを静的に取得するようになりました (index.php) 。
public function addTpl() {
global $zip;
if(!isset($_GET['url']) || empty($_GET['url'])) {
$_GET['url'] = 'index';
}
$front = '_zip/_templates/_front/'. $zip['Template']['Front'];
$back = '_zip/_templates/_back/'. $zip['Template']['Back'];
if(strpos($_GET['url'], 'backend') !== false) {
if(file_exists($back . '/')) {
if(file_exists($back . '/index.php')) {
ob_start();
include($back . '/index.php');
$this->tpl .= ob_get_contents();
ob_end_clean();
} else {
if($zip['Template']['Front'] == 'Refresh/multi-page') {
ob_start();
include($back . '/404.php');
$this->tpl .= ob_get_contents();
ob_end_clean();
} else {
die(zipError('File Not Found', 'The file <b>' . secure($_GET['url']) . '</b> could not be found. Please re-check the URL; If you were directed here using a link, please report that link <b><a href="mailto:IntactDev@gmail.com">here<a/>.</b>'));
}
}
} else {
die(zipError('Template Not Found', 'The template <b>' . $zip['Template']['Front'] . '</b> could not be found. Please check your configuration file for a mistake.'));
}
} else {
if(file_exists($front. '/')) {
if(file_exists($front. '/' . secure($_GET['url']) . '.php')) {
ob_start();
include($front. '/' . secure($_GET['url']) . '.php');
$this->tpl .= ob_get_contents();
ob_end_clean();
} else {
if($zip['Template']['Front'] == 'Refresh/multi-page') {
ob_start();
include($front. '/404.php');
$this->tpl .= ob_get_contents();
ob_end_clean();
} else {
die(zipError('File Not Found', 'The file <b>' . secure($_GET['url']) . '</b> could not be found. Please re-check the URL; If you were directed here using a link, please report that link <b><a href="mailto:IntactDev@gmail.com">here<a/>.</b>'));
}
}
} else {
die(zipError('Template Not Found', 'The template <b>' . $zip['Template']['Front'] . '</b> could not be found. Please check your configuration file for a mistake.'));
}
}
}
get 値に backend が含まれているかどうかをコードで確認し、その後に文字列が含まれるスラッシュがあるかどうかを確認するにはどうすればよいですか? ここに私のhtaccessがあります
RewriteEngine On
RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1