1

I'm using Zend Framework and come up with a situation of forwarding a request to another action in same controller.

I'm forwarding the request from create to save. What I want to do is to check (from saveAction) whether the request is forwarded or a direct request (without using any additional variables or parameters)

init() function will be triggered twice for each forwarding (one for create and one for save), and it would be better check from init() too.

class Cms_UserController extends Zend_Controller_Action {

    public function init() {
        parent::init();

        // some code here
    }

    public function createAction() {

        if (!$this->getRequest()->isPost()) {
            // forwarding to cms/user/save
            return $this->_forward('save');
        }

        // do some stuff for POST request
    }

    public function saveAction() {
        // I want to check whether the request is
        // forwarded from 'createAction' or from any action
        // or a direct request to cms/user/save
    }

}
rajukoyilandy
  • 5,341
  • 2
  • 20
  • 31

1 Answers1

3

Hope this will help you:

public function lastAction(){
    $request=$this->getRequest()->getParams();
    $request['action']; //you can get corresponding actions here
}
public function testAction(){
    return $this->_forward('last');
}
Munawer Aziz
  • 196
  • 1
  • 7
  • That worked!!! thanks man. FYI, I've used a short cut method `$this->getRequest()->getParam('action')` that will give 'test', and `$this->getRequest()->getActionName()` will give 'last' :) – rajukoyilandy Nov 28 '12 at 13:08
  • Great work @Munawer Aziz and rajukoyilandy ...your previous collegue..unnikrishnan – coolguy Nov 28 '12 at 15:00