codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.3k stars 1.89k forks source link

$pager->links() not working inside view layouts #3164

Closed mwauramuchiri closed 4 years ago

mwauramuchiri commented 4 years ago

The pager does not render the view in view layouts obviously because displayLinks() method uses render() and not include() method.

<!-- TEMPLATE -->
<?= $this->extend('layout') ?>
<?= $this->section('content') ?>
<?= pager->links() ?>
<?= $this->endSection() ?>

SUGGESTION

My workaround would be to use the layout property of $this->view to determine whether to use the right render method.


$view = return $this->view->setVar('pager', $pager);

if ( isset($this->view->layout) )
{
    return $view->include($this->config->templates[$template]);
}

return $view->render($this->config->templates[$template]);

At the moment I have extended the service and overridden the method to use include because I'm working with layouts in the whole project.

michalsn commented 4 years ago

I can't really recreate it. Can you give us any more details like CodeIgniter version? Maybe a quick example of how to recreate it?

mwauramuchiri commented 4 years ago

Right, I am using codeigniter version 4.0.3 Sorry, to recreate what exactly?

mwauramuchiri commented 4 years ago

the view instance in CodeIgniter\Pager\Pager knows if it's rendering inside a view layout and the view render method does not work inside view layouts (from the docs, include() is the recommended method). I was thinking to have a simple if else that will do ->include($template) if the pager is being rendered inside a view layout.

paulbalandan commented 4 years ago

Correct me if I'm wrong. Shouldn't this be not a problem? I mean, using include will just call render under the hood, so there isn't must difference between the two.

https://github.com/codeigniter4/CodeIgniter4/blob/6c7c36d2ac95b30d15caf9b2734949a23433f7bc/system/View/View.php#L510

I don't know if it is a typo or not.

<!-- TEMPLATE -->
<?= $this->extend('layout') ?>
<?= $this->section('content') ?>
<?= pager->links() ?> // shouldn't this be <?= $pager->links() ?>
<?= $this->endSection() ?>
michalsn commented 4 years ago

I also see no difference between those two, except for $saveData default value.

<?= pager->links() ?> // shouldn't this be <?= $pager->links() ?>

Looks like a typo to me.

michalsn commented 4 years ago

Okay... I'm closing this, since it doesn't seem to be a bug, but feel free to continue the conversation - especially if you can provide more examples. Thanks.

mwauramuchiri commented 4 years ago

Oh mehn. Yes, it is a typo