【发布时间】:2016-04-08 16:30:12
【问题描述】:
在我的 Sitecontroller actionIndex 中,我有一个 dataProvider 按类别过滤产品,然后将它们显示在 listView 中:
$model = new Produtos();
$searchModel = new ProdutosSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
// get the posts in the current page
$post = $dataProvider->getModels();
return $this->render('index',
['imagem1' => $imagem1, 'imagem2' => $imagem2,'imagem3' => $imagem3, 'model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
在我的站点/index.php 中,我渲染视图以显示产品:
<?php echo $this->render('//produtos/view2', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]); ?>
在我的 produtos/view2 中,我有:
<nobr>
<?= $form->field($searchModel, 'categoria')->dropDownList(ArrayHelper::map(Categorias::find()->all(), 'categoria','categoria'), ['prompt'=>Yii::t('yii', 'Todos os produtos...')]) ?>
<?= Html::submitButton(Yii::t('app', 'Pesquisar'), ['class' => 'btn btn-warning']) ?>
</nobr>
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => '_view2',
'summary' => '',
]); ?>
在我的 produtos/_view2.php 我有:
<?= DetailView::widget([
'model' => $model,
'options' => ['class' => 'detail1-galeria-view2'],
'attributes' => [
// cria um array com a fotografia, em que carrega a path no campo fieldName da bd
[
'attribute'=>'',
//'value'=>$model->foto,
'value'=>Html::a(Html::img(Yii::$app->getUrlManager()->getBaseUrl() . "/" .$model->foto, ['width'=>'230', 'height' => "256"]), $model->foto),
'format' => 'raw',
],
[
'attribute'=>'',
'value'=>$model->nome,
],
[
'attribute'=>'',
'value'=>$model->categoria,
],
[
'attribute'=>'',
'value'=>$model->descricao,
],
[
'attribute'=>'',
'value'=>$model->valor.' '.'€',
],
// info
[
'attribute'=>'',
'format' => 'raw',
// nesta hiperligação passo o valor do model->nome deste registo para encomendas/create
'value'=> Html::a(Yii::t('app','Comprar'), Url::toRoute(['encomendas/create', 'nome' => $model->nome, 'preco' => $model->valor])),
],
],
]) ?>
当我按所有产品过滤类别时,所有项目并排显示,但是当我按某些类别(例如衣服)进行过滤时,过滤后的产品的渲染完成了,但在这里和那里都有 GAPS。过滤器删除不属于活动类别的产品和 listView 呈现间隙。
这里是一些空白的屏幕截图:
如何解决?
编辑: 下面的 css 类几乎解决了这个问题:
.detail1-galeria-view2{
margin-bottom:40px;
width: 380px; /* this value fixed almost all gaps for the detailView */
float:left;
color:#201c0e;
font-weight:500;
font-size:12px;
text-align:center;
}
【问题讨论】:
标签: php listview yii2 dataprovider detailview