동일한 라우팅 구문으로 자체 프레임 워크를 만들었습니다. 여기에 내가 할 수있는 작업은 다음과 같습니다
사용 mod_rewrite는이 $_GET
변수의 매개 변수 (같은 /some/path/{info}
)를 저장하기 위해 내가 params
전화 :
RewriteRule ^(.+)(\?.+)?$ index.php?params=$1 [L,QSA]
매개 변수를 구문 분석하고 전 세계적으로이 기능을 사용하여 저장 :
public static function parseAndGetParams() {
동적 적절한 페이지 }
노선 : 여기
// get the base page string, must be done after params are parsed
public static function getCurPage() {
global $params;
// default is home
if(empty($params))
return self::PAGE_HOME;
// see if it is an ajax request
else if($params[0] == self::PAGE_AJAX)
return self::PAGE_AJAX;
// see if it is a multi param page, and if not, return error
else {
// store this, as we are going to use it in the loop condition
$numParams = count($params);
// initialize to full params array
$testParams = $params;
// $i = number of params to include in the current page name being checked, {1, .., n}
for($i = $numParams; $i > 0; $i--) {
// get test page name
$page = strtolower(implode('/', $testParams));
// if the page exists, return it
if(self::pageExists($page))
return $page;
// pop the last param off
array_pop($testParams);
}
// page DNE go to error page
return self::PAGE_ERROR;
}
}
값 그것이 적어도 특정 페이지로 가장 구체적인 페이지를 찾습니다이다 . 또한 프레임 워크를 벗어난 운동을 통해 완전한 제어을 얻을 수 있습니다. 어딘가에 버그가있는 경우이를 해결할 수 있습니다. 프레임 워크에서 이상한 해결 방법을 찾을 필요가 없습니다.
이제는 $params
이 전역이므로 매개 변수를 사용하는 페이지는 단순히 $params[X]
을 호출하여 작업합니다. 프레임 워크가없는 친숙한 URL.
페이지를 추가하는 방법은 pageExists($page)
호출에서 보았던 배열에 넣는 것입니다.자신의 마이크로 라우팅 프레임 워크 -
// if ajax, include it and finish
if($page == PageHelper::PAGE_AJAX) {
PageHelper::includeAjaxPage();
$db->disconnect();
exit;
}
그리고 짜잔 : AJAX를 들어
내가 특별한 IF에 넣어 호출합니다.
[URL 재 작성] (http://en.wikipedia.org/wiki/URL_rewriting)에 대해 이야기하고 있습니까? –
예, 그 이름을 알지 못했습니다. –
원래 문구로 되돌 렸습니다. 자신과 같은 개념에 익숙하지 않은 사용자를 생각하고 동일한 문구를 검색합니다. 현재의 표현을 유지하고 URL 재 작성이 무엇인지 설명하십시오. –