A
A
Alexander Ampleev2018-03-30 11:56:51
Yii
Alexander Ampleev, 2018-03-30 11:56:51

Why listview distorts links in the view?

there is such code in the view

<li><a href="site/change-sort/?sort=showAll">показать все</a></li>

it is used in list view page with listview.
Everything works well with this listview configuration:
echo ListView::widget([
        'dataProvider' => $listDataProvider,
        'itemView' => $elView,

        'options' => [
            'tag' => 'div',
            'class' => 'postslist',
            'id' => 'post-list',
        ],

        'layout' => "{items}",

        'itemOptions' => [
            'tag' => 'div',
            'class' => 'post',
        ],

            'emptyText' => 'Ничего не найдено..',

            'pager' => [
                'firstPageLabel' => 'Первая',
                'lastPageLabel' => 'Последняя',
                'nextPageLabel' => 'Следующая',
                'prevPageLabel' => 'Предыдущая',
                'maxButtonCount' => 10,
            ],

    ]);

but if you add a pager to the layout like this:
echo ListView::widget([
        'dataProvider' => $listDataProvider,
        'itemView' => $elView,

        'options' => [
            'tag' => 'div',
            'class' => 'postsslist',
            'id' => 'post-list',
        ],

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

        'itemOptions' => [
            'tag' => 'div',
            'class' => 'post',
        ],

            'emptyText' => 'Ничего не найдено..',

            'pager' => [
                'firstPageLabel' => 'Первая',
                'lastPageLabel' => 'Последняя',
                'nextPageLabel' => 'Следующая',
                'prevPageLabel' => 'Предыдущая',
                'maxButtonCount' => 10,
            ],

    ]);

then, when you go to the second page of the pager (the url becomes like this " domen.com/site/index?page=2&per-page=25 ")
instead of such a link in the view
<li><a href="site/change-sort/?sort=showAll">показать все</a></li>

turns out like this
<li><a href="site/site/change-sort/?sort=showAll">показать все</a></li>

why is this happening? The code in the view is the same, so I conclude that the listview somehow affects this ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-03-30
@Ampleev

Good afternoon.
Is that how you write the link in the view?
If so, then use the helpers that are in yii2, do not be lazy to write them. Avoid a lot of problems by using helpers.
Or so, and at the output you get what they showed?
And then you need to look at the settings of your urlManager ().
Also consider the slash in the address and they will behave differently.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question