Reputation: 478
I have a view in which I have used GridView
and DetailView
. In my controller I am sending a model via it's ID. So in this way my GridView
is working.
Controller 1
public function actionViewcreated($id)
{
$model=$this->findModel($id);//the id of created form
/*print_r($model);
exit();*/
$id = $model->id;
$created_by = $model->created_by;
$issuer = $model->issuer;
$store = $model->store_id;
$admin = $model->admin_incharge;
$pm = $model->project_manager;
.....
// my other code
return $this->render('viewcreated', [
'dataProvider' => $dataProvider,
'model' => $this->findModel($id),
'id'=> $model->id
/*'searchModel' => $searchModel*/
]);
}
View
$this->title = $model->id;
$this->title = 'Outward Gate Pass';
$this->params['breadcrumbs'][] = $this->title;
.
.
.
.
<?= DetailView::widget([
'model' => $model,
'attributes' => [
//'id',
[
'label'=>'OGP Serial #',
'value' => function($d)
{
return $d->id;
}
],
[
'label' => 'Created By',
'value' => function ($d) {
if(is_object($d))
return $d->created->name;
},
/* 'filter' => Html::activeDropDownList($searchModel, 'created_by', \app\models\User::toArrayList(), ['prompt' => "Users", 'class' => 'form-control']),*/
],
'created_at',
[
'label' => 'Store',
'value' => function ($d) {
if(is_object($d))
return $d->store->name;
return ' - ';
},
//'filter' => Html::activeDropDownList($searchModel,'store_id',\app\models\Stores::toArrayList(),['prompt' => "Stores", 'class'=>'form-control']),
],
'status',
[
'label' => 'Issued To',
'value' => function ($d) {
if(is_object($d->user))
return $d->user->username;
return ' - ';
},
//'filter' => Html::activeDropDownList($searchModel, 'issuer', \app\models\User::toArrayList(), ['prompt' => "Users", 'class' => 'form-control']),
],
'admin_incharge',
'project_manager',
],
]) ?>
<br>
<?= GridView::widget([
'dataProvider' => $dataProvider,
/*'filterModel' => $searchModel,*/
'columns' => [
['class' => 'yii\grid\CheckboxColumn'],
'Meter Serial Number',
'Issued To',
'Store',
],
]); ?>
<form>
<p>
<a href="<?= URL::toRoute('ogpheader/viewsetpdf')?>" type="submit" class="btn btn-primary" name="issue_pdf">Set PDF</a>
<br/>
</p>
</form>
The resulted view:
Now want to send my both GridView
and DetailView
into a new controller. For
New Controller
public function actionViewsetpdf($id)
{
$model = $this->findModel($id);
print_r($model);
exit();
}
Here I just want to see the values in my model. But when I click on the Set PDF
button I always get
Bad Request (#400) Missing required parameters: id
I am stuck to it as I don't know why it's not showing me the data.
Any help would be highly appreciated.
Upvotes: 1
Views: 1632
Reputation: 411
The bad request error means that you are not passing a GET parameter with the name id
your request string generation should look something like
<?= URL::toRoute(['ogpheader/viewsetpdf','id'=>$model->id])?>
Upvotes: 1