Friday, February 24, 2012

Re: Form input selected

yes you should never use those named params without checking for them
first

and - I would put the logic in the controller
passing it on to the view via $this->request->data
thats a cleaner approach than using the form here for the selected
value


On 24 Feb., 20:51, heohni <heidi.anselstet...@consultingteam.de>
wrote:
> Hi,
>
> I am using the ajax pagination and my url looks like this:
> /search/cat:12/city:67/sleeps:1/price:2
>
> I have for each a dropdown input select:
> $this->Form->input('cat', array('options' => $getCategories,
> 'selected' => $this->request->params['named']['cat']));
>
> But what I want to know, what is best practice, because on first call
> of the form and their input selects I get the error:
> Undefined index: cat
>
> Which is clear for me, but do I have really to check before is the
> value is present? Like
> $selectedCat = ($this->request->params['named']['cat'])?$this->request->params['named']['cat']:'';
>
> echo $this->Form->input('cat', array('options' => $getCategories,
> 'selected' => $selectedCat));
>
> Is this best practice?

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: