Yii2 - Detailview Widget Float Left

Yii2 - DetailView widget float left

I solved it by myself.

The trick was to create another class with position:relative; and put the detailview widget inside it.

Here's the code for the view:

<div class="detail-disposal">
<?= DetailView::widget([
'model' => $model,
'options' => ['class' => 'detail1-view'],
'attributes' => [
//'titulo',
'noticia',
// cria um array com a fotografia, em que carrega a path no campo fieldName da bd
[
'attribute'=>'fotodir',
'value'=>$model->fotodir,
'format' => ['image',['width'=>'230','height'=>'200']],
],
],
]) ?>

and the css style used in app/web/css:

.detail-disposal{
position:relative;
width:100%;
}

DetailView CSS:

.detail1-view {
margin-left:20px;
margin-bottom:20px;
float:left;
width: 300px;
border:1px solid #000;
}

Now the detailview widget appears side by side every time a model is called.

How to call another DetailView::widget from another model in one view YII2?

You can use two DetailView widgets in the same view, there is no problem.

In controller:

use yii\web\NotFoundHttpException;

...

public function actionView($id)
{
$model1 = $this->findModel($id);
$model2 = ModelName::find()->where(['id' => ...])->one();
if (!$model2) {
throw new NotFoundHttpException('Second model not found');
}

return $this->render('view', [
'model1' => $model1,
'model2' => $model2,
]);
}

In view:

<div class="col-md-6">
<?= DetailView::widget([
'model' => $model1,
'attributes' => [
'name',
],
]) ?>
</div>

<div class="col-md-6">
<?= DetailView::widget([
'model' => $model2,
'attributes' => [
'name',
],
]) ?>
</div>

More info on DetailView widget.

fuction() not working in Detailview yii2

Follow the final answer as below:

view.php

 <?= DetailView::widget([
'model' => $model,
'attributes' => [
'userID',
'userEmail:email',
'userName',
'userMobile',
'userBirthDate',
'userGender',
[
'attribute' => 'interestName',
'format' => 'raw',
'label' => 'Interest',
'value' => $model->getviewinterest(),
],
'userStatus',
'userType',
],
]);

?>

Users.php(Model)

public function getviewinterest() 
{
foreach ($this->userinterest as $userinterest)
{
$interestNames[] = $userinterest->interestName;

}

if(!empty($interestNames)){
return implode("<br/>", $interestNames);
}else{
return "(not set)";
}
}

Yii2 Render an image in DetailView

Try this:

[
'attribute'=>'photo',
'value'=>$model->photo,
'format' => ['image',['width'=>'100','height'=>'100']],
],

Yii2 two DetailView side by side

You can unse bootstrap grid
In view you can palce the detailView in two separated bootstrap column

    <div class="col-sm-6 col-md-6 col-lg-6" >

<?= DetailView::widget([
'model' => $modelBuyer,
......

?>
</div>
<div class="col-sm-6 col-md-6 col-lg-6" >

<?= DetailView::widget([
'model' => $modelSeller,
......

?>
</div>

in controller simply pass the two models in render

       return $this->render('your_view', [
'modelBuyer' => $modelBuyer,
'modelSeller' => $modelSeller,
]);


Related Topics



Leave a reply



Submit