I'm still pretty new to the whole nette/latte framework and I'm currently trying to figure out pagination. I have tried to mostly follow the official documentation (which "somewhat" worked), but as soon as I try to implement the n:href attribute, I get the following error:
PHP message: PHP Fatal error: Uncaught Latte\CompileException: Unexpected attribute n:href
This is where the error occurs:
{if !$paginator->isFirst()}
<a n:href="default, 1">First</a>
|
<a n:href="default, $paginator->page-1">Previous</a>
|
{/if}
Page {$paginator->getPage()} of {$paginator->getPageCount()}
{if !$paginator->isLast()}
|
<a n:href="default, $paginator->getPage() + 1">Next</a>
|
<a n:href="default, $paginator->getPageCount()">Last</a>
{/if}
I really hope someone can help me here.
I have already tried to change the code from the documentation in a couple of different ways, but that didn't work either :(
Like this for example:
{if !$paginator->isFirst()}
<a n:href="default, $paginator->getPage() = 1">First</a>
|
<a n:href="default, $paginator->getPage() - 1">Previous</a>
|
{/if}
I have also tried to leave out the n:href all together, but keeping it seems to be my best bet for solving the problem.
This main part of my php code:
$latte = new Engine;
$latte->setTempDirectory(__DIR__ . '/temp');
$latte->setAutoRefresh(true);
$dsn = "mysql:host=" . DBHOST . ";dbname=" . DBNAME . ";charset=UTF8";
$database = new Connection($dsn, DBUSER, DBPASS);
$articles = [];
$articles = $database->fetchAll('SELECT * FROM production.requests WHERE archived = "1" ORDER BY order_date ASC;');
// Paginator setup
$paginator = new Paginator;
$paginator->setItemCount(count($articles));
$paginator->setItemsPerPage(2); // items per page
$paginator->setPage(1); // actual page number
$items = [];
$items = $database->fetchAll('SELECT * FROM production.requests WHERE archived = "1" ORDER BY order_date ASC LIMIT ? OFFSET ?', $paginator->getLength(), $paginator->getOffset());
$parameters = [
'items' => $items,
'paginator' => $paginator,
];
$latte->render(__DIR__ . '/templates/main/test.latte', $parameters);
You can't get n:href
to work, because it's part of nette/application
package. You are using plain latte, so you of course can't generate links to application presenters.
You need to use whole framework or implement your own n:href
macro like in application package: https://github.com/nette/application/blob/master/src/Bridges/ApplicationLatte/Nodes/LinkNode.php