0

Estoy tratando de tomar el parámetro(144452) enviado por get el cual se encuentra en la url:

http://localhost/yii/basic/web/index.php?r=crud/editar/144452

Quisiera hacerlo asi para tener una url mas limpia en vez de poner &id=144452 pero no he conseguido hacerlo. He tratado así:

Yii::$app->request->get('id')

Pero no me funciona.

2

1 respuesta 1

0

Ya la variable la tienes declarada en el controlador, solo el mandar el id al form.

 public function actionUpdate($id)
{
    $model = $this->findModel($id);

    if ($model->load(Yii::$app->request->post()) && $model->save()) {
        return $this->redirect(['view', 'id' => $model->id]);
    }

    return $this->render('update', [
        'model' => $model,
        'id'  => $id,

    ]);
}

Luego desde la vista update update.php

     <?= $this->render('_form', [
            'model' => $model,
            'id'  => $id,
        ]) ?>

Y en el formulario _form.php

Echo $id; 

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.