E
E
EVOSandru62015-10-19 16:08:34
JavaScript
EVOSandru6, 2015-10-19 16:08:34

How to create an action with parameters in yii?

Good afternoon,

It is indicated in the documentation. that you can create an Action by specifying actionId :

www.yiiframework.com/doc/api/1.1/CController#creat...

But nothing is said here about how to pass parameters there...

I have 2 questions:

1. Is it possible do what I described above?
2. Is there a more loyal ajax way to switch from actionCreate to actionUpdate . Support for uploading images is required. The fact is that some form blocks should open only after saving the main model.
3. Perhaps it's better to turn it around by replacing scripts like that?

While I have such a code, but the place where I'm atisAjaxRequest block create action , doesn't work:

public function actionCreate()
  {
    if (Yii::app()->request->isAjaxRequest ) 
    {
      $model = new Hotels();
      if(isset($_POST['Hotels']))
      {
        $model->setAttributes($_POST['Hotels'], true);
        if(!$model->save())
          My::printArr($model->getErrors());

            // Вызов чужого контроллера и action 
     $p = Yii::app()->createController('sadmin/hotels'); // /update
            $act = $p[0]->createAction('update', ['id'=>$model->id]);
            $act->run();
      Yii::app()->end();
    }
    else
    {
      $this->layout = '//layouts/form1';
      $model = new Hotels();
      $model->exist = Hotels::STATUS_PUBLIC;
      $firms = Firms::model()->getAll();
      $this->render('create',
        [
          'model'=>$model,
          'firms'=>$firms,
        ]);
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
EVOSandru6, 2015-10-20
@EVOSandru6

Yii::app()->runController('sadmin/hotels/update/id/'.$id);

D
Dmitry Donkovtsev, 2015-10-19
@Demetriy


example.com/index.php?r=hotels/create&id=5&price=cheap
public function actionCreate($id, $price) {

}

I think so.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question