Chen Kinnrot
Chen Kinnrot

Reputation: 21015

How to pass data in url using cakephp?

I wanted to now if there is a way to pass a simple string inside url and cakephp some how put it inside one of the inputs of my form without any code writing on view side? I tried calling this->set("bla","bla"); the field name is bla but nothing changed in view

Upvotes: 2

Views: 8396

Answers (2)

Nik Chankov
Nik Chankov

Reputation: 6047

As I understood the question you want to have something like this:

in the url you have something like:

http://yourserver.com/controller/action?search=string

and you want to put this "string" in the search field, right?

Then let's imagine that your field's name is data[search_field]. (I am skipping the model, because for my example it's not needed, but it's possible the name to be data[Model][search_field]).

Then in your controller's action you have to do following:

$this->data['search_string'] = $this->params['url']['search'];

Upvotes: 3

bancer
bancer

Reputation: 7525

You can pass values in the url by using html helper. Try:

echo $this->Html->link('View Some Page', array(
    'controller' => 'yourController',
    'action' => 'view',
    1, // id
    '?' => array('yourField' => 'valueToPass'))
);

Upvotes: 2

Related Questions