Re: set checkboxes on multiple forms

2009-01-02 Thread brian

On Fri, Jan 2, 2009 at 11:53 PM, brian  wrote:
> I have an admin_index page for a model that requires a listing for
> each row, which includes a *separate* form with a couple of
> checkboxes. The controller action is:
>
> public function admin_index()
> {
>$this->data = $this->paginate();
> }
>
> Now, in the view, I cannot figure out how to get the FormHelper to
> properly set the "checked" attribute on these checkboxes. Why doesn't
> this work?
>
> (I'm not interested in editing multiple records with a single form, btw.)
>
> foreach($this->data as $k => $foo)
> {
> ?>
> create('Foo', array('action' => 'edit')) ?>
> hidden("Foo.${k}.id") ?>
> 
>
>
>
>()
>
>
>input("Foo.${k}.something") ?>
>
>
>input("Foo.${k}.something_else") ?>
>
>
>submit('edit') ?>
>
>
> 
> end() ?>
>
> I thought FormHelper was able to do this if $this->data is set. I know
> that I can just type out the form markup, but ...
>

I just clued in to the fact that the data array was in the wrong form.
I'm using contain to grab the User's name info and the array looked
like:

Array
(
[0] => Array
(
[Foo] => Array
(
[id] => 1
[bar] => 1
[another_field] => 0
[user_id] => 3
)

[User] => Array
(
[first_name] => ...
[last_name] => ...
[organisation_name] => ...
[id] => 3
[label] => ...
)

)
...

Of course, I need:

Array
(
[Foo] => Array
(
[0] => Array
(
[first_name] => ...
[last_name] => ...
[organisation_name] => ...
[id] => 1
[label] => ...
[bar] => 1
[another_field] => 0
[user_id] => 3
)
...

I solved it by using the most excellent Set class.

$tmp = $this->paginate();

$this->data['Foo'] = Set::merge(
Set::extract($tmp, '{n}.User'),
Set::extract($tmp, '{n}.Foo')
);
unset($tmp);

I had to put the User extraction first in the merge params so that
Foo->id wouldn't get clobbered because contain grabs User->id even if
it's not in the fields list.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



set checkboxes on multiple forms

2009-01-02 Thread brian

I have an admin_index page for a model that requires a listing for
each row, which includes a *separate* form with a couple of
checkboxes. The controller action is:

public function admin_index()
{
$this->data = $this->paginate();
}

Now, in the view, I cannot figure out how to get the FormHelper to
properly set the "checked" attribute on these checkboxes. Why doesn't
this work?

(I'm not interested in editing multiple records with a single form, btw.)

foreach($this->data as $k => $foo)
{
?>
create('Foo', array('action' => 'edit')) ?>
hidden("Foo.${k}.id") ?>




()


input("Foo.${k}.something") ?>


input("Foo.${k}.something_else") ?>


submit('edit') ?>



end() ?>

I thought FormHelper was able to do this if $this->data is set. I know
that I can just type out the form markup, but ...

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---