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 .
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,
));
}
'id'=>'hour-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
't2_id',
'from_time',
'to_time',
't1.date', t1 represents the relationship with date table specified in model hour
't1.comment',
array(
'class'=>'CButtonColumn',
),
),