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