0

I'm a Cake newbie, and I'm looking to post a querystring value into a controller method, but always reload the view with the querystring intact. Currently I have the below snippet.

public function something()
{
     if($this->request->query !=null )
        $date = $this->request->query["date"];

}

<?php echo $this->Form->create('setup',array('action' => 'something?date=2013','id'=>'setup-form','role'=>'form') ); ?>

Any advice on why something() doesn't redirect to something?date=2013 on its default render? Do I need to do some special routing?

1 Answer 1

3

In CakePHP 2, you can include query string parameters in $url parameters like so:

array('action' => 'something', '?' => array('date' => '2013'))

CakePHP will build the query string and append it to the matched URL in your routing configuration.

(Note: You may need to pass FormHelper::create an entire URL, generated from HtmlHelper::url, instead of using the "shorthand" technique.)

Sign up to request clarification or add additional context in comments.

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.