2016-09-09 13 views

答えて

1
$dataprovider後、あなたのコントローラで

:私はこれがyii2の基本的な使用の場合には、それになると思う

$count=$dataProvider->getTotalCount(); 

if($count==1){ 

$dataProvider->getModels(); 
// get id and redirect view 
//redirect to view 

}else{ 

//redirect to gridview or listview 

} 
+0

ありがとうございました。 foreachの代わりに、$ dataprovider-> getModels()[0] ['id']を使用してIDにアクセスできます。 @jithin – Parvvee

0

..

 $searchModel = new PostSearch(); // Search Model can be created by gii 
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 

     $count= $dataProvider->getTotalCount(); 

       if($count==1){ 

        $a = $dataProvider->getModels(); 
        $id = $a[0]['id'] ; // accessing 2nd level array elements or $dataProvider->getModels()[0]['id']; 

        return $this->render('view', [ 
         'model' => $this->findModel($id), //findModel($id) is protected function in the controller 
        ]); 

       } 
関連する問題