Some time ago a decison was made at my workplace to "get rid of’ our Domino environment and to look at other development environments. The decsion was made to go with PHP and MS SQL and we chose Yii as the framework. It is really exciting and also at time frustrating as we come to terms with this new Yii world.
I am comfortable now creating models, controllers and views using Gii and listing, creating and managing the tables and their records - Yii is just fantastic.
I am currently developing an application that has for example two table:
Table A and Table B
Table A:
id
profilename
business
site
type
Table B:
id
idA
personname
I have used yiic and Gii to create the application.
What I would like to know is when the View for model A is displayed I create a field listofnames that is a text box,. The other attributes profilename, business, site and type are already created by default for me. In this text box, listofnames, I can add the following; name1, name2, name3, name4, name5. When I save/create what I would like to do is get a handle to listofnames field and create entries in table A, also, when I load the form again I would like those list of names to populate my listofnames field and when I do a save again I need to ensure I remove those entries from table B and re-insert them (in the event listofnames has changed)
I know how to do this in normal PHP but what I was hoping for was some guidance on how to do it using just Yii.
thank you for yr reply however I feel i did not explain my problem well. What I I have is the following:
Table A: with columns id, rname, rtype
Table B: with columns id, idA, pname
What I am trying to achieve is an entry for
Table A eg, 125, application developer, newbie
and entries for
Table B eg
1, 125, John Smith
2, 125, Penny Smith
3, 125, Frank Smith
Now, the model created for Table A has attributes for id, rname and rtype. I created an additional attribute called $listofnames of type textbox. On the form this textbox is used to make name entries eg John Smith; Penny Smith; Frank Smith
In my ‘A’ model (for table A) how can I get a handle to the names in the textbox listofnames so I can then insert each name in Table B
I have tries $model->listofnames, $this->listof names but nothing sems to work in so far as getting a handle to the data.
In controller I am trying to add code in the Create action:
public function actionCreate()
{
$model=new Staffroleprofile;
// AppDev - START
// create variable to the model Staffrolename...
$model_staffrolename = new Staffrolename;
// AppDev - END
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Staffroleprofile']))
{
$model->attributes=$_POST['Staffroleprofile'];
if($model->save())
//AppDev - START
// we have saved our new staffroleprofile record and now have an id...
// what we want to do is now get the data entered in the attribute '$selectedrolenames', convert it into an array
// and make entries in the table 'staffrolename'...
//$model_staffrolename->$this->idstaffroleprofile=$model->id;
//$model_staffrolename->username=$model->selectedrolenames;
//$model_staffrolename->save();
//INSERT INTO [appcommondata].[dbo].[staffrolename]
//([idstaffroleprofile]
// ,[username])
// VALUES
//(10
// ,'some data')
//$model->attributes=$_POST['Staffroleprofile'];
//$values = "($model->id, 'somedata')";
//$values = "($model->id, $this->selectedrolenames)";
//$_POST['selectedrolenames']
//$sql = 'INSERT INTO staffrolename (idstaffroleprofile, username) VALUES ' . $values;
//$command = Yii::app()->db->createCommand($sql);
//$command->execute();
$model->StaffroleProfile;
// AppDev - END
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
Lots of commented out coed as I am trying stuff…
Hope this explanation helps in describing my issue (apart from a lack of Yii experience ( )