我希望$startdate
动态地等于当前日期。
这是我的代码:
public function actionNextcourses($startdate = '2016-04-02' )
{
$nextcourses = Courses::find()->where('start_date > :startdate', [':startdate'=>$startdate])->all();
return $this->render('nextcourses', ['nextcourses'=>$nextcourses]);
}
public function actionPrevcourses($startdate = '2016-04-02')
{
$prevcourses = Courses::find()->where('start_date < :startdate', [':startdate'=>$startdate])->all();
return $this->render('prevcourses', ['prevcourses'=>$prevcourses]);
}
答案 0 :(得分:1)
您可以使用null默认值来解决:
public function actionNextcourses($startdate = null )
{
if($startDate == null) $startDate = date('Y-m-d');
$nextcourses = Courses::find()->where('start_date > :startdate', [':startdate'=>$startdate])->all();
return $this->render('nextcourses', ['nextcourses'=>$nextcourses]);
}
答案 1 :(得分:0)
PHP不允许为函数参数设置默认动态值。