0

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.

Vogel612
  • 5,620
  • 5
  • 48
  • 73
shychotc
  • 25
  • 7

2 Answers2

1

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.

gb5256
  • 191
  • 11
0

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 !

gb5256
  • 191
  • 11
  • the gii is an autogenerated form, mine is a custom made one because it needs to submit in 2 different controllers that's why I'm asking the $_POST for chtml... – shychotc Feb 01 '15 at 11:32
  • are these two different controllers or two different actions of the same controller? – gb5256 Feb 01 '15 at 12:14
  • two different models actually, only one action in the a controller that would submit to two different models.. sorry for misinformation – shychotc Feb 01 '15 at 12:40
  • 1
    It looks like this answer completely lost it's raison d'étre – Vogel612 Feb 01 '15 at 14:44