Insert Multiple Records Using One Textfield

i want to develop timesheet

i am newbie in yii,i dnt know how to insert multiple records at a time

i have one table with id,date,from time,to time,comment

so i want to insert from time and to time multiple times

that means for a same date from time and to time will change

this want to do in single form

sample data i wil show

suppose

[b]date:2013/04/22

from time:10:00 am ,to time: 12:00 pm

from time: 12:30 pm ,to time:02:30 pm

comment:studied yii framework[/b]

i want to insert this data into table in single form

any help will appreciated

please help

thanks and regards in advance

Hello,

So better way to create 2 table like,

Table1

-t1_id

-date

-comment

Table2

-t2_id

-from_time

-to_time

-t1_id(reference key)

you can save it as json object in one table but that will make you life harder, lets say for instance you decide to search you data, it will be very difficult, you might as well add a second table now .

could you please give me code for inserting data into two table

i dnt know how to insert data for two tables

also how to show this two table data in one view

is it easy way?

also when use two table model can i insert multiple row at a time

please mention about that code

actualy i dnt know about that concepts in yii

i just started yii framework

so any help will be appreciated…:)

can i insert data into two table with one form??

please help me

i want enter from time to time multiple times

but i cannot do with this code

can u please show how to insert multiple times into two table

created two tables and also created two models

inserted using single form into two table

but can not do admin action with this shows error

here is the code

please help me

hourcontroller.php

public function actionCreate()

{


	$model=new Hour;


	$date=new date();





	if(isset($_POST))


	{





		if(isset($_POST['Hour'])) {


	$model->attributes=$_POST['Hour'];


	$model->save();


	}





		if(isset($_POST['date'])){


	$date->attributes=$_POST['date'];


			$date->save();


	}


	//Redirect to your target page 


		


	}


	/*if($date->save()){


	$this->redirect(array('view','id'=>$model->t2_id));}*/





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


	'model'=>$model,


	'date'=>$date,


	));


}








public function actionUpdate($id)


{


	$model=$this->loadModel($id);





	// Uncomment the following line if AJAX validation is needed


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





	if(isset($_POST['Hour']))


	{


		$model->attributes=$_POST['Hour'];


		if($model->save())


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


	}





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


		'model'=>$model,


	));


}








public function actionDelete($id)


{


	$this->loadModel($id)->delete();





	// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser


	if(!isset($_GET['ajax']))


		$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));


}








public function actionIndex()


{


	$dataProvider=new CActiveDataProvider('Hour');


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


		'dataProvider'=>$dataProvider,


	));


}





[color="#FF0000"][u][b]/*not working this,commented portions are mine,but that is also not working*/[/b][/u][/color]


public function actionAdmin()


{


	$model=new Hour('search');


	//$date=new date('search');


	$model->unsetAttributes();


	//$date->unsetAttributes();  // clear any default values


	if(isset($_GET['Hour']))


	{


		/*if(isset($_GET['date']))


		{*/


			$model->attributes=$_GET['Hour'];


			/*$date->attributes=$_GET['date'];


		}*/


	}





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


		'model'=>$model,


		//'date'=>$date


	));


}

model/hour.php

public function rules()

{


	


	return array(


		array('t1_id', 'numerical', 'integerOnly'=>true),


		array('from_time, to_time', 'length', 'max'=>145),


		


		array('t2_id, from_time, to_time, t1_id', 'safe', 'on'=>'search'),


	);


}








public function relations()


{


	//


	return array(


		't1' => array(self::BELONGS_TO, 'date', 't1_id'),


	);


}








public function attributeLabels()


{


	return array(


		't2_id' => 'T2',


		'from_time' => 'From Time',


		'to_time' => 'To Time',


		't1_id' => 'T1',


	);


}








public function search()


{


	





	$criteria=new CDbCriteria;


	$criteria->alias = 'i';


	$criteria->with = "date";


	$criteria->compare('t2_id',$this->t2_id);


	$criteria->compare('from_time',$this->from_time,true);


	$criteria->compare('to_time',$this->to_time,true);


	$criteria->compare('t1_id',$this->t1_id);


	$criteria->join= 'JOIN date d ON (i.t2_id=d.t1_id)';


	


	return new CActiveDataProvider($this, array(


		'criteria'=>$criteria,


	));


}

views/hour/index.php

<h1>Timesheet</h1>

<?php

	/*&#036;this-&gt;widget('zii.widgets.CListView', array(


'dataProvider'=&gt;&#036;dataProvider,


'itemView'=&gt;'_view',

)); */

$this->widget(‘bootstrap.widgets.BootGridView’, array(

'id'=&gt;'timesheet-view-grid',


'dataProvider'=&gt;&#036;dataProvider,





'columns'=&gt;array(


			't1.date',


			'from_time',


			'to_time',


			't1.comment',


			


			array(


				


				'class' =&gt; 'CButtonColumn',


				'template' =&gt; '{view}',


				


				),


			),


		


		));

?>

views/hour/admin.php

<?php echo CHtml::link(‘Advanced Search’,’#’,array(‘class’=>‘search-button’)); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial(’_search’,array(

'model'=&gt;&#036;model,

)); ?>

</div><!-- search-form -->

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'id'=&gt;'hour-grid',


'dataProvider'=&gt;&#036;model-&gt;search(),


'filter'=&gt;&#036;model,


'columns'=&gt;array(


	't2_id',


	'from_time',


	'to_time',


	't1.date', t1 represents the relationship with date table specified in model hour


	't1.comment',


	array(


		'class'=&gt;'CButtonColumn',


	),


),

)); ?>

Hi, shrus

Have you already found the answer to this question? I also have problems like this.

Hi,

I hope this link will help

http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/