ListView > itemView from different controller

Hi,

inside my views/site/index.php I’ve added code listed below to display news container:




    $dataProvider = new ActiveDataProvider([

        'query' => News::find(),

        'sort' => ['defaultOrder' => ['date' => SORT_DESC]],

        'pagination' => [

            'defaultPageSize' => 5,

            'pageParam' => 'strona'

        ],

    ]);

    

    echo(ListView::widget([

        'layout' => "{items}\n{pager}",

        'dataProvider' => $dataProvider,

        'itemView' => '_news',

        'pager' => ['class' => 'yii\widgets\LinkPager']

    ]));



problem is, that my _news.php file (itemView) is basically inside views/news folder.

Currently I have to make a copy inside views/site to make it work.

How can tell ListView to look for itemView in different folder? I’ve tried ‘itemView’ => ‘…\news\_news’ but without success.

When itemView is a string,

it is passed as paramter to render() method of ListView.

http://www.yiiframework.com/doc-2.0/yii-base-view.html#render()-detail

In that context, you can pass view name with different format, as you can see in documentation.

You shold solve with:

/news/_news.php