2

/mycontroller/search を実行すると "/mycontroller" しか表示されませんが、メソッドにいるときに "/mycontroller/search" をsearch取得するにはどうすればよいですか? メソッドにいるときに "/mycontroller/other" を取得するにはどうすればよいですかother

class Mycontroller  extends Zend_Controller_Action
{ 
  private $url = null;
  public function otherAction() { 
   $this->url .= "/" . $this->getRequest()->getControllerName();
   echo $this->url;  // output: /mycontroller
   exit;
  }
  public function searchAction() { 
   $this->url .= "/" . $this->getRequest()->getControllerName();
   echo $this->url; // output: /mycontroller
                    // expect: /mycontroller/search
   exit;
  }
}
4

2 に答える 2

1

/mycontroller/searchを期待する理由:

public function searchAction() { 
   $this->url .= "/" . $this->getRequest()->getControllerName();
   echo $this->url; // output: /mycontroller
                    // expect: /mycontroller/search
   exit;
  }

あなたはコントローラを求めているだけです。

これはうまくいくでしょう:

 public function searchAction() { 
    $this->url = '/'. $this->getRequest()->getControllerName();
    $this->url .= '/' . $this->getRequest()->getActionName();

    echo $this->url; // output: /mycontroller/search

    echo $this->getRequest()->getRequestUri(); //output: requested URI for comparison

    //here is another way to get the same info
    $this->url = $this->getRequest()->controller . '/' . $this->getRquest()->action;
    echo $this->url;

 exit;
 }
于 2012-02-05T12:35:06.470 に答える