luyadev / luya

LUYA is a scalable web framework and content management system with the goal to please developers, clients and users alike.
https://luya.io
MIT License
812 stars 207 forks source link

Issues with controller switching #1771

Closed makroxyz closed 6 years ago

makroxyz commented 6 years ago

What steps will reproduce the problem?

in a view

<?= ListView::widget([
    'dataProvider' => $dataProvider,
    'itemView' => '_product',
    'layout' => "<div class=\"text-right\">{pager}</div>\n<div class=\"row animated fadeInLeft\">{items}</div>\n<div class=\"text-right\">{pager}</div>",
    'pager' => [
        'class' => LinkPager::class,
        'options' => ['class' => 'pagination pagination-sm'],
    ],
]) ?>

What is the expected result?

The 2 pagers (top and bottom) should work in the same way

What do you get instead? (A Screenshot can help us a lot!)

Second pager has wrong urls inside button (cms/default)

The problem is: ListView renders a page for each item, so the render() method is called for every item.

This fires EVENT_BEFORE_RENDER/View::EVENT_AFTER_RENDER and ModuleReflection.php (rows 244, 253) switches controller at every event. So after the last item controller is switched to original, and the bottom pager creates urls with wrong controller.

Hope it helps

nadar commented 6 years ago

I assume this is part of a module which is implemented into a cms page as module block or as page type module.

makroxyz commented 6 years ago

Yes it is

Il 16 feb 2018 15:51, "Basil" notifications@github.com ha scritto:

I assume this is part of a module which is implemented into a cms page as module block or as page type module.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/luyadev/luya/issues/1771#issuecomment-366256232, or mute the thread https://github.com/notifications/unsubscribe-auth/AB-Vvb3qcvqGWARo9qiCtfrLVkSo731Tks5tVZYIgaJpZM4SIcC3 .

nadar commented 6 years ago

@makroxyz thank you for the report!

nadar commented 6 years ago

@makroxyz are you running the latest dev-master?

nadar commented 6 years ago

On my system it seem to work with the latest dev-master. Your example

<?= ListView::widget(['dataProvider' => $provider,
    'itemView' => '_product',
    'layout' => "<div class=\"text-right\">{pager}</div>\n<div class=\"row animated fadeInLeft\">{items}</div>\n<div class=\"text-right\">{pager}</div>",
    'pager' => [
        'class' => LinkPager::class,
        'options' => ['class' => 'pagination pagination-sm'],
    ],
]); ?>

(i used the news module)

here a screenshot from the links generated from the pagination (the bottom one)

bildschirmfoto 2018-02-18 um 09 04 00

the example setup:

bildschirmfoto 2018-02-18 um 09 04 48
nadar commented 6 years ago

This is what the ActiveDataProvider looks like:

$provider = new ActiveDataProvider([
            'query' => Article::find()->andWhere(['is_deleted' => false]),
            'sort' => [
                'defaultOrder' => $this->module->articleDefaultOrder,
            ],
            'pagination' => [
                'route' => $this->module->id,
                'params' => ['page' => Yii::$app->request->get('page')],
                'defaultPageSize' => $this->module->articleDefaultPageSize,
            ],
        ]);
makroxyz commented 6 years ago

I'm using latest dev-master

My ActiveDataProvider doesn't have pagination definition. Try to delete pagination definition in ActiveDataProvider and you'll see it will generate 2 different urls for top and bottom pager... and this is not good in my opinion.

The only workaround I found is:

$provider = new ActiveDataProvider([
        ....
        'pagination' => [
            'route' => $this->getRoute(),
        ],
]);

Hope it helps

nadar commented 6 years ago

ok, now i see the problem.

nadar commented 6 years ago

@makroxyz i pushed a fix which should fix the problem. Could you please try? Thanks

makroxyz commented 6 years ago

It works now! Thanx!