2012-03-02 2 views
0

저는 Zend_Rest_Controller를 확장하여 RESTful 서비스를 구현했습니다. 이 서비스는 훌륭하게 작동합니다. 실제로 RESTful 동작을하는 컨트롤러는 하나뿐입니다. 그래서 부트 스트랩에서 컨트롤러에 대한 나머지 경로를 추가했습니다.젠드 레스트 (zend rest) 라우트가 기본 컨트롤러에 대한 라우팅을 엉망으로 만들었습니다.

protected function _initRestRoute() 
{ 
    $this->bootstrap('frontController'); 
    $frontController = Zend_Controller_Front::getInstance(); 
    $restRoute = new Zend_Rest_Route($frontController, array() , array('default' =>  array('MyserviceController'))); 
    $frontController->getRouter()->addRoute('rest', $restRoute); 

} 

포털 zend 응용 프로그램을 실행할 때 문제가 발생합니다. 인덱스 컨트롤러 레이아웃의 링크는 URL을 구성 할 때 action 매개 변수에서 누락됩니다. 예를 들어 네트워크 컨트롤러의 작업 홈 페이지에 대한 색인 레이아웃의 링크는 다음과 같습니다.

$this->url(array('controller'=>'network','action'=>'homepage','module'=>'default')); 

이 "로컬 호스트/프로젝트 이름/공공/네트워크/홈페이지"대신 반환 "로컬 호스트/프로젝트 이름/공공/네트워크"를 반환해야합니다. 이 동작은 레이아웃이 기본 컨트롤러, 즉 IndexController에 의해로드 된 경우에만 발생합니다. 부트 스트랩에서 zend rest route를 제거하면 라우팅 문제가 사라집니다. 나머지 컨트롤러가 요청한 컨트롤러를 언급하는 한 문제가되지 않아야합니다. 하지만 이것은 기본 컨트롤러 라우팅에 영향을 미치고 있습니다.

$this->url(array('controller'=>'network','action'=>'homepage','module'=>'default'), 'default'); 

나 :

$this->url(array('controller'=>'network','action'=>'homepage','module'=>'default'), NULL, TRUE); 

가 작동 할 수

답변

0

이것은 일반적인 문제 일반적으로 같은 뭔가 해결 될 것으로 보인다.

'module'=>'default'이 기본 컨트롤러 디렉토리 인 경우 /application/controllers의 경우 모듈 옵션을 경로에서 생략 할 수 있습니다.

여기에 전체 URL 메소드가 있습니다. 재설정 옵션에 대한 설명을 참고하십시오.

/** 
    * Generates an url given the name of a route. 
    * 
    * @access public 
    * 
    * @param array $urlOptions Options passed to the assemble method of the Route object. 
    * @param mixed $name The name of a Route to use. If null it will use the current Route 
    * @param bool $reset Whether or not to reset the route defaults with those provided 
    * @return string Url for the link href attribute. 
    */ 
    public function url(array $urlOptions = array(), $name = null, $reset = false, $encode = true) 
    { 
     $router = Zend_Controller_Front::getInstance()->getRouter(); 
     return $router->assemble($urlOptions, $name, $reset, $encode); 
    } 
+0

그래, 고마워. – biker46s