1

Greetings

I want to display data from my Atividades model in Yii2

My AtividadesController has the following code for actionView2

public function actionView2()
{
    $query = new Query;
    $dataProvider = new ActiveDataProvider([
        'query' => $query->from('Atividades'),
        'pagination' => [
            'pageSize' => 20,
        ],
    ]);

    // get the posts in the current page
    $posts = $dataProvider->getModels();
    return $this->render('view2', ['dataProvider' => $dataProvider, 'posts' => $posts]);

}

And in my View 2 i have the following List View that appears with the message showing 4 of 4 items, but doesn't shows the items

<?= ListView::widget([
    'dataProvider' => $dataProvider,
]); ?>

In Y1.xx i had a property called 'attributes' for display the model fields

How can i display the model fileds in Yii2 inside this Listview

Many thanks in advance

1
  • The Bold and the Beautiful! Commented May 31, 2016 at 12:34

1 Answer 1

4

I have solved it by myself :)

It was not hard

In my View2 Written the following code

 <?= ListView::widget([
    'dataProvider' => $dataProvider,
    'itemView' => '_view2',
]); ?>

And then duplicated an original view file, changed its name to _view2, put it in the same folder, and style it has needed

In my ActividadesController changed the actionView2 code to:

public function actionView2()
{
    $dataProvider = new ActiveDataProvider([
    'query' => Atividades::find(),
    'pagination' => [
    'pageSize' => 20,
],
]);

// get the posts in the current page
$posts = $dataProvider->getModels();
return $this->render('view2', ['dataProvider' => $dataProvider]);
}

_View2 code

<?= DetailView::widget([
    'model' => $model,
    'attributes' => [
        //'id',
        'atividade',
        'descricao:ntext',
        //'ativo',
    ],
]) ?>

SOLVED

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.