1

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.

2
  • Can you clarify your question a bit? Do you mean passing parameters to the next controller action? Commented Jan 13, 2011 at 16:17
  • 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) Commented Jan 13, 2011 at 16:23

3 Answers 3

3

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
}
Sign up to request clarification or add additional context in comments.

2 Comments

thx, but im need simplify and invisible method to SET parameters at View. At Form way, user can read params too. AJAX way is not so cute because at the next step i need to redirect user to new page this generated form. Mbe any ideas?
There is no way to securely and invisibly store parameters in a view.
1

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 Comment

thank you, Seb! Can you write example code with Zend_Session?
1

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.