Hi,

I'm pretty new to cakephp, so thank in advance for any input.

I am attempting to build a series of forms in a view with form helper
based on a set of data from a find('all') in my controller.

The layout is that I have a course table and a schedule table, with
each schedule record having a course_id and each course record having
many schedules.

I set it up so on entry of a new course, the course->add action
automatically adds three schedule records, one for each day of class,
automatically incrementing each one day with start and end times and
etc (based on a datetime field in the course add form). A consecutive
three day class is therefore default for each course.

But I also needed on new course entry to confirm/edit each scheduled
day of class, (especially datetimes), and also to be able to add
descriptions for each day and etc, so I redirect from the add course
action to a schedule->edit($course_id) action which takes $course_id
as an input and:

$this->data = find('all',array('conditions'=>array('course_id'=>
$course_id)));

(for some reason findByCourse_id($course_id) would not work)

The idea I thought would be to loop through the three results in the
view using formhelper to build the three forms, which could each be
examined and updated separately.

I spent some time on this problem and discovered that formhelper is
not particularly helpful in this case - building the form didn't work
automagically in the loop. I fussed around with it a bit but I get a
bit muddy on how the various helpers and components and conventions
deal with their arrays of data - still learning - so I'm not at all
clear on if this problem is dead simple, or if I'm trying to do
something impossible, or if there's another solution looking me in the
face.

I did google the problem quite a bit but could not find anything to
help me - although that doesn't mean nothing is out there. This
article is similar, and suggests the problem:
http://bakery.cakephp.org/articles/view/multirecord-helper-behavior

One peculiar thing I found was that I could get partial results from
form helper in the loop if I prepended a incrementing number to the
create and fields like this:


$i=0;
foreach($schedules as $schedule)
 /* also $this->data = $schedules from controller because I believe
form helper uses $this->data? */

   $form->create("$i.Schedule")  // ie: '1.Schedule'
   $form->input("Schedule.$i.id") // ie: 'Schedule.1.id'
   $form->input("Schedule.$i.start_date") // ie: 'Schedule.1.id'

   $i++

endforeach;


Form helper populated 2 out of three of these forms with data from the
set. the first on ($i=0) was always blank. But it didn't convert the
start_date to a set of date select fields.

Anyway, I'm in over my head here and any help would be appreciated.


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to