Tabular Input Create (3 models)

Hi

I managed to figure out how to tabular update, but I’m having problems with create.

I have 3 tables = PROJECT, TASK, SERVICE.

PROJECT(id) has many TASKs(project_id).

TASK(service_id) has one SERVICE(id).

Now I need to list as many tasks as there is services, 1 TASK per SERVICE.

So if 10 SERVICEs, TASKs look like this:

  1. textField, dropDown, …

  2. textField, dropDown, …

  1. textField, dropDown, …

What is the best way to make the form and actionCreate() controller?

Here is my actionCreate() from current PROJECT controller.




public function actionCreate()

	{

		$project=new Project;

                $service=Service::model()->findAll(array("order"=>"category_id ASC, id ASC"));

                $task=new ProjectTask;


		// Uncomment the following line if AJAX validation is needed

		//$this->performAjaxValidation($project);

                //$this->performAjaxValidation($task);

                

		if(isset($_POST['Project'], $_POST['ProjectTask']))

		{

                        

			$project->attributes=$_POST['Project'];

                        $task->attributes=$_POST['ProjectTask'];

                        $valid=$project->validate();

                        $valid=$task->validate() && $valid;

                        

                        

                        if($valid) {

                                $project->save(false);

                                $task->save(false);

                                $this->redirect(array('view','id'=>$project->id));

                        }

		}


		$this->render('create',array(

			'project'=>$project,

                        'task'=>$task,

                        'service'=>$service,

		));

	}



Current form




...

        <?php if($project->isNewRecord): ?>

        <?php foreach ($service as $i => $item): ?>

        <tr id="<?php echo $item->category->id."-".$item->id;?>" style="display: none;">

            <td>

                <?php 

                $theService = sprintf("%d.%d %s", $item->category->id, $item->id, $item->title);

                echo $theService; ?>

            </td>

            <td><?php echo CHtml::activeDropDownList($task, "[$i]employee_id", CHtml::listData(Employee::model()->findAll(), 'id', 'name'), array('class' => 'span2', 'empty'=>'')); ?></td>

            <td><?php echo CHtml::activeDropDownList($task, "[$i]initiative", array("bht"=>"BHT", "client"=>"Klient"), array('class' => 'span2')); ?></td>

            <td><?php echo CHtml::activeTextArea($task, "[$i]comment"); ?></td>

            <td><?php echo CHtml::activeTextField($task, "[$i]deadline", array('class' => 'span2')); ?></td>

            <td><button type="button" class="btn danger" onclick="hideRow('<?php echo $item->category->id."-".$item->id;?>', '<?php echo $i; ?>')">X</button></td>

        </tr>

        <?php endforeach; ?>

...



Just bumping the thread up ::)

I am also having same problem, can any body please help me by providing the solution.

Maybe the extension multimodelform can help.

From the documentation:

group -> your project

member -> your task with formConfig: service as dropdownlist, initiative(dropdownlist),comment (textArea) …