V
V
Vyacheslav_Shilov2020-06-22 17:34:02
Yii
Vyacheslav_Shilov, 2020-06-22 17:34:02

Why isn't a parameter passed to the controller action?

Why is the "id" parameter not being passed to the controller action? urlManager uncommented
Address bar looks like this: http://parms/blog/site/index/id/6

Controller action code:

public function actionIndex($id)
  {
    $this->render('index', array('id'=>$id));
  }


View controller code (index.php):
<?php
   /* @var $this SiteController */
   /* @var $id int */

   $this->pageTitle=Yii::app()->name;
  
   echo $id;
   CVarDumper::dump($id);
   echo $id;

   ?>


Shows "null" when displayed in the browser

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-06-22
@Vyacheslav_Shilov

The problem is obviously not in rendering and routes, but in passing the parameter itself. You have not shown the link anywhere and what parameter is passed there. Perhaps you are $idpassing in a parameter null. Look carefully. You can check this very simply by executing a simple command not in the template, but in the controller:

public function actionIndex($id)
{
     var_dump($id); die();
}

Also don't forget about return:
public function actionIndex($id)
{
    return $this->render('index', array('id'=>$id));
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question