I have a chtml::textfield
and what I need is whenever I input a value and click on the chtml::button
, it should update two different models.
but I don't know how process the $_POST['id']
in the controller.
I am still trying to figure out what you actually want... So lets assume you have two fields where you want to store Value_1 in YourModel1 and Value 2 in YourModel2. In your controller that you call on Submit:
public function actionSubmit()
{
if (isset($_POST['Value_1'])) {
$model_1 = new YourModel1;
$model_1->attributes=$_POST['Value_1'];
$model_1->save();
}
if (isset($_POST['Value_2'])) {
$model_2 = new YourModel2;
$model_2->attributes=$_POST['Value_2'];
$model_2->save();
}
}
Please note that for simplicity I am not taking care of any validation of your data etc. Besides this I guess (because you are not saying) that you want to create a new Model, not updating an existing one.
Try to use Gii as a starting point.
Here is a wiki about how to do that in Yii-1.
Gii will create basic things for you, including a create and update form and the appropriate actions in the controller to take the users input and even puts it into the database for you.
That is the best start for you and then you can easily adjust it to your needs. Gii is the Yii-Newbies best friend !