I have these 2 methods for my previous and next records buttons in my task model
public function getNext()
{
return Task::find()
->where(['>', 'id', $this->id])
->orderBy(['id' => SORT_ASC])
->one();
}
public function getPrev()
{
return Task::find()
->where(['<', 'id', $this->id])
->orderBy(['id' => SORT_DESC])
->one();
}
this is working fine but after the last record and before 1 record I get this error Missing required parameters: id. how can I display a custom message instead of this error or disable/hide the next button when it reaches the last record
code in the view file
<?= Html::a('Previous',
['/pmt/task/task-view', 'id' => $model->prev->id],
['class'=>'btn btn-primary btn-xs']);
?>
<?= Html::a('Next',
['/pmt/task/task-view', 'id' => $model->next->id],
['class'=>'btn btn-primary btn-xs']);
?>
Just put an if statement around the next button?
<?= Html::a('Previous',
['/pmt/task/task-view', 'id' => $model->prev->id],
['class'=>'btn btn-primary btn-xs']); ?>
<?php if($next = $model->next) {
<?= Html::a('Next',
['/pmt/task/task-view', 'id' => $next->id],
['class'=>'btn btn-primary btn-xs']); ?>
<?php } ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.