ZendFramework - 如何知道执行哪个控制器和哪个特定方法?

发布于 2025-01-02 09:55:55 字数 668 浏览 0 评论 0原文

当我执行 /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山人契 2025-01-09 09:55:55

$this->getRequest()->getActionName(); 返回操作名称。
您还可以使用 $_SERVER['REQUEST_URI'] 来获取您想要的内容。

$this->getRequest()->getActionName(); returns action name.
you also may use $_SERVER['REQUEST_URI'] to get what you want.

后来的我们 2025-01-09 09:55:55

为什么你会期望/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;
 }

why would you expect /mycontroller/search from this:

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

you are only asking for the controller.

this would work:

 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;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文