Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3756992
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:56:15+00:00 2026-05-19T09:56:15+00:00

I’m developing a simple application with CakePhp, and need some help on creating a

  • 0

I’m developing a simple application with CakePhp, and need some help on creating a multi-record edit form using some related data.

The application I’m developing is pretty straightforward, its main purpose is managing students records: updating, deleting, changing a student from one group to another, the usual suspects.

The relevant tables of the database are:

group = (id, teacher, classroom, etc)
groups_students=(groupID, studentID, since, until)
students = (id, name, last_name, etc)
assitance = (id, assitance, date)
assistance_students (studentID, assitanceID, meta_information )

As you might have gathered from the tables above, the application is supposed to aid in recording assitance. Which is where I’m having some issues.

What I want to do is this:

  • Have the user select a group
  • In de detail group, I’ll have an action called “Register Assistance”
  • Register assitance should redirect to a view in wich for every student belonging to that group, the user can see the student’s assitance, edit them, and save. Something like this:

    example of table/form

In which A stands for “Absent” and P for “Present” and the user can edit everyone, and the save.

I just don’t know how to go about that? How do I manage that? I’ve managed to create a multi-edit form for the assitance, but adding the related data is a pain, I don’t know if I should query the students from the groups controllers and then pass that to the action to register assitance, or manage all the logic inside the assitance controller?

Any help would be great,

thanks!

Edit: Here’s the output of $this->Student->find('first');

Array ( 
    [Alumno] => Array ( 
                     [id] => 14 
                     [tipo] => dni 
                     [dni] => 2321312312 
                     [apellido] => COQUITO 
                     [nombre] => Pepe 
                     [carrera] => Composición Musical 
                     [creado] => 2011-01-08 17:59:00 
                     [modificado] => 2011-01-08 17:59:00 
                     ) 
        )

The output is in spanish. Alumno = Student, nombre= first name, apellido= last_name.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:56:15+00:00Added an answer on May 19, 2026 at 9:56 am

    Well, I managed to find a solution to this. I was waiting to see if anyone found something better, as I’m pretty sure my solution is far from the best, but here it goes, in case someone finds this question in the future.

    My issue was that I needed, for every group I selected to register assitance:

    1. Every student that belonged to that group
    2. All the assitances of the students belonging to that group

    Now, in order to make use of the Form helper to edit those assitences (and after, the saveAll() method), I needed $this->data to have ann array like this:

    Array
    (
        [Assitance] => Array
        (
            [5] => Array
                (
                    [id] => 5
                    [date] => 2011-01-09
                    [assitance] => A
                    [updated] => 2011-01-16 21:32:00
                    [created] => 2011-01-16 21:32:00
                )
    
            [6] => Array
                (
                    [id] => 6
                    [date] => 2011-03-09
                    [assitance] => A
                    [updated] => 2011-01-16 21:32:00
                    [created] => 2011-01-16 21:32:00
                )
    
         )
    
    )
    

    at the same time, though, I needed each student linked to his or her assitances, to be able to loop trough them, and display the edit forms for every assitance in a table like the one in the question:

    alt text

    What I ended up doing is this

    1. First, I query all the students belonging to the selected group.
    2. For each student get all his/her assitances .

    so, for each student, I ended up having an array like this:

    Array
        (
            [Student] => Array
                (
                    [id] => 12
                    [last_name] => LASARTE
                    [name] => Julia
                    [created] => 2011-01-08 16:35:00
                    [updated] => 2011-01-08 16:35:00
                    [assitance] => Array
                        (
                            [0] => Array
                                (
                                    [Assitance] => Array
                                        (
                                            [id] => 4
                                            [date] => 2011-01-09
                                            [assitance] => z
                                            [updated] => 2011-01-16 20:51:00
                                            [created] => 2011-01-16 20:51:00
                                        )
    
                                    [assitance_studenty] => Array
                                        (
                                            [id] => 2
                                            [student_id] => 12
                                            [assitance_id] => 4
                                            [comision] => 0
                                        )
    
                                )
    
                        )
                )
    
        )
    
    )
    

    Now, with that, I have the information I need in order to display the table and create the forms, but I still need the assitances data in $this->data, so the form helper can create the from displaying the correct information, and afterwars, saveAll() updates the rows in the database correctly.

    What I needed to do was turn the array of $students into an structure like the one at the beginning of the post. Enter the Set Class:

    $formated_students = Set::combine($students, '{n}.students.id', '{n}.students');
    $assitance =  Set::extract('/presentes/Assistance', $formated_students);
    $this->data['Assistance'] = Set::combine($assistance,  '{n}.Assistance.id', '{n}.Assistance');
    

    I’m pretty sure the first to lines (formating the students array in order to extract the assitance) can be done with just one Set::extract or Set::classicExtract, but this worked and regular expressions are really not my thing, so.

    After that, It’s just a matter of looping trough the data and making the table:

    <?php 
    echo $form->create('Assistance', array('url' => array('controller' => 'Comisions', 'action' => 'register_assitance')));
    foreach ($students as $student) { ?>
        <tr><td>><?php echo $student['students']['last_name'].", ".$student['students']['name']; ?></td>
        <?php foreach ($student['students']['assitance'] as $asstiance) { ?>
            <td><?php echo $form->input('Assistance.'.$assitance['Assistance']['id'].'.id');
            echo $form->input('Assistance.'.$assitance['Assistance']['id'].'.assistance', array( 'label' => false, 'size' => 1)) ?></td>
        <?php } ?>
    </tr>
    <?php } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.