Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mwauramuchiri opened this issue Jun 24, 2020 · 7 comments
Closed

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

mwauramuchiri opened this issue Jun 24, 2020 · 7 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@mwauramuchiri
Copy link

mwauramuchiri commented Jun 24, 2020

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.

@mwauramuchiri mwauramuchiri added the bug Verified issues on the current code behavior or pull requests that will fix them label Jun 24, 2020
@mwauramuchiri mwauramuchiri changed the title $pager->links not working inside view layouts $pager->links() not working inside view layouts Jun 24, 2020
@michalsn
Copy link
Member

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
Copy link
Author

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

@mwauramuchiri
Copy link
Author

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
Copy link
Member

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.

public function include(string $view, array $options = null, $saveData = true): string

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
Copy link
Member

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
Copy link
Member

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
Copy link
Author

Oh mehn. Yes, it is a typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

3 participants