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

3

$this->getRequest()->getActionName();返回动作名称。你也可以$_SERVER['REQUEST_URI']用来得到你想要的。

于 2012-02-05T11:45:39.800 回答
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 回答