ZendFramework - 如何知道执行哪个控制器和哪个特定方法?
当我执行 /mycontroller/search 时,它仅显示“/mycontroller”,但是 当我在 search
方法中时,如何获取“/mycontroller/search”,当我在 other
方法中时,如何获取“/mycontroller/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;
}
}
When i execute /mycontroller/search it shows only "/mycontroller" but
how do i get "/mycontroller/search" when i am in search
method, how do i get "/mycontroller/other" when i am in other
method.
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$this->getRequest()->getActionName();
返回操作名称。您还可以使用
$_SERVER['REQUEST_URI']
来获取您想要的内容。$this->getRequest()->getActionName();
returns action name.you also may use
$_SERVER['REQUEST_URI']
to get what you want.为什么你会期望/mycontroller/search:
你只需要控制器。
这会起作用:
why would you expect /mycontroller/search from this:
you are only asking for the controller.
this would work: