2011-04-10 5 views
4

ZendFramework에서 ~으로 시작하는 URL을 특수 컨트롤러 및 작업으로 라우팅하여 다른 URL이 ~으로 올바르게 시작하지 않도록하고 싶습니다.특수 문자로 시작하는 라우팅 URL

예를 들어 두 개의 URL의 라우팅 아래 참조 :

mysite.com/~user 

mysite.com/admin 

내가 어떻게 할 수 있습니까?

답변

1

시도는 부트 스트랩

// Get the instance of the router 
$router = Zend_Controller_Front::getInstance()->getRouter(); 

// Set up a new regex router to match routes starting with ~ 
$route = new Zend_Controller_Router_Route_Regex(
    '(^\~)', 
    //This route should use a 'special' controller 
    array(
     'controller' => 'special', 
     'action'  => 'index' 
    ) 
); 

// Add the new route to the router 
$router->addRoute('archive', $route); 
,369 내에서 이것을 사용

라우터에 라우팅 된 요청에 응답하려면 Special 컨트롤러가 필요합니다.

+0

오류 메시지가'잘못된 컨트롤러가 지정되었습니다 (~ 사용자) '입니다. –

+0

당신은 어떤 URL을 사용합니까? –

+0

나는 이것을 시도한다 :'http : // localhost : 8080/~ user'. –

-1

특별히 zend에 대해서는 확실하지 않지만 URL 라우터가 비즈니스를 수행하기 전에 해쉬 조회 테이블을 추가하는 것이 가장 좋습니다.

그래서 mod_rewrite는이 변환 말할 수 : mysite.com/~user

이에

: mysite.com/index.php?path=~user

당신이 이런 짓을 할 것이다 :

$path = $_GET['path']; 

$url_mod = array(
    '~user'=>'my_other_controller', 
    'admin'=>'my_other_controller', 
); 

if(isset($url_mod[$path)) { 
$path = $url_mod[$path]; 
} 
+0

질문이 있으시면, 나는 라우팅 URL 또는 ZendFramework에서 사용할 수있는 접근 방법이 필요합니다. –