Search code examples
phpzend-frameworkzend-controller

ZendFramework - How to know which controller and which specific method is execued?


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;
  }
}

Solution

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