1
votes

I have one page (view) and I want to pass some parameters from this page (view) to controller (where im going to generating form etc...). How i can pass some parameters from view to controller?

I know one way: link with GET parameters (?foo=bar&..) but in this way user see his params. Mbe it possible to pass as POST? How?

Thx a lot.

3
Can you clarify your question a bit? Do you mean passing parameters to the next controller action?Seb Barre
yep. Another action controller. Ex: clinic page, and i want to create advertise, so i want pass clinic id to advertise controller (to action create)0dd_b1t

3 Answers

3
votes

To pass POST variables to your Zend Framework application, simply submit a POST request. You can do this either by submitting a form to the URL that's bound to the controller action, or via an AJAX request.

When working inside a controller action, you get POST variables using:

// for the whole POST array
$this->getRequest()->getPost();

// for a specific variable
$this->getRequest()->getPost('var');

Also helpful, when processing forms is to determine if a request is actually a POST operation:

if ($this->getRequest()->isPost()) {
  // process form
}
1
votes

You can use Zend_Session to pass variables from request to request without exposing their values in the view. The only thing that will be passed to the client is the session id, not any of the session data.

So in theory you could set values in the session from inside your view file (with a PHP block in your phtml template that doesn't render anything to the client) and then retrieve those values in subsequent controller actions.

1
votes

If you want to pass data via form post the above answer is ok..if you wanna post via url then you need to use zend routers step 1: Create a routes.xml file in application folder with content

<?xml version="1.0" encoding="UTF-8"?>
<routes>
    <manual>
        <route>/foo/bar/:key</route>
        <defaults>
            <controller>yourController</controller>
            <action>YourAction</action>
        </defaults>

    </manual>
    </routes>

step :2

In your boostrap.php add this,

protected function _initRoutes()
            {
                $routefile = new Zend_Config_Xml(APPLICATION_PATH.'/routes.xml');
                $router = Zend_Controller_Front::getInstance()->getRouter();
                $router->addConfig($routefile);
                return $router;


            }

Thats it..when ever an url for the form www.eg.com/foo/bar/5 occurs, you can get the value 5 in YourController,Youraction by this way $this->_request->getParam('key');