我有以下代碼,我想使用名爲鏈接而不是id的字段查找模型。但是,它似乎沒有產生任何結果。我可以在哪裏弄錯?它返回404如何在Yii中使用除id以外的字段查找記錄2
public function actionView($link)
{
$model = News::find()->where(['link'=>$link])->all();
return $this->render('view', [
'model' => $model,
]);
}
注:在搜索模式,我曾嘗試添加此:
$query->andFilterWhere([
'id' => $this->id,
'link'=>$this->link,
'category' => $this->category,
'date' => $this->date,
'userid' => $this->userid,
'featured' => $this->featured,
]);
檢查網址是否正確 – jithin
我使用搜索友好的URL中包含自定義URL經理[鏈接] HTTP://本地主機/項目/前端/網絡/控制器/視圖/ 1正在工作,但 [鏈接] http:// localhost /項目/前端/網絡/控制器/視圖/鏈接不是 – KMarto