1
我正在使用Yii2
-advanced模板。我想從我的'index.php'中取'img_id
'中的siteController
的功能。Yii2:從控制器的html中獲取圖像ID
我在 '的index.php' 代碼如下:
<?php
$m = $dataProvider->getModels();
foreach ($m as $dp) {
echo '<a id ="img_id" class="" href="http://localhost/efa-webv1/frontend/web/index.php?r=site/subcat&id='.$dp['bmc_id'].'" method="post">';
echo "<img src = '"."http://localhost/efa-webv1/backend/web/".$dp['bmc_image']."' />";
echo '<center><font color = "white">'.$dp['bmc_name'].'<font/></center>';
echo '</a>';
}
?>
而我試圖把它在我的siteController
爲:
public function actionSubcat() {
$searchModel = new BusinessMainCategoriesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->pagination->pageSize = $dataProvider->getTotalCount();
$query = new \yii\db\Query;
$query->select('*')->from('business_sub_categories')->where(['bmc_id' => $_POST["img_id"]]); //trying to get img_id using this
$query->createCommand();
$dataProvider2 = new ActiveDataProvider([
'query' => $query,
'pagination' => false,
]);
return $this->render('subcat', [
'dataProvider' => $dataProvider, 'dataProvider2' => $dataProvider2]);
}
但如果我用「$ _ POST [「img_id」]',它表示未定義索引「img_id」。
所以,請幫助我讓我理解它。現在
If I used Yii2 ancher tag, I get unexpected result as -
使用[yii2錨標籤](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#a%28%29-detail),它會比這更容易。 –
首先檢查你會得到img_id in $ _POST – jilesh
檢查它在函數print_r($ _ POST)的啓動中使用; – msvairam