VisualPaginator nekanonizuje page-1
- srigi
- Nette Blogger | 558
Pri pouziti mierne upraveneho VisualPaginatora z GITu mi nefunguje kanonizacia prvej stranky. Funguju obe URL
- blablabla.dev/
- blablabla.dev/?paginator-page=1
DefaultPresenter
public function renderDefault()
{
$page = $this['paginator']->page;
$posts = $this->db->table('post')->where('published IS NOT NULL');
$this->template->page = $page;
$this->template->posts = $posts;
}
protected function createComponentPaginator($name)
{
return new VisualPaginator($this, $name);
}
sablona
{block #content}
{var $pageSize = 2}
{foreach $posts->order('published DESC')->page($page, $pageSize) as $post}
{include '@_post.latte', post => $post}
{/foreach}
{control paginator, count => $posts->count('*'), pageSize => $pageSize}
bootstrap.php
...
$container = $configurator->createContainer();
$container->router[] = new Route('tag/<tag>', 'Default:tag');
$container->router[] = new Route('post/<slug>', 'Default:post');
$container->router[] = new Route('<presenter>', 'Default:default');
return $container;
VisualPaginator
<?php
use Nette\Application\UI\Control,
Nette\Utils\Paginator;
class VisualPaginator extends Control
{
...
/** @persistent */
public $page = 1;
public function getPaginator()
{...}
public function render($options = NULL)
{
$paginator = $this->getPaginator();
$paginator->setItemCount($options['count']);
$paginator->setItemsPerPage($options['pageSize']);
$page = $paginator->page;
...
}
public function loadState(array $params)
{...}
}
Paginuje to krasne, len ma stve, ze nefunguje ta kanonizacia. A pritom ten param je oznaceny ako @persistent. Requirements-Checker mi hlasi uplne vsetko zelene. Persistentne parametre s default hodnotou na urovni presentera mi tiez funguju – odskusal som si minimalny test s persistentnym parametrom $lang.
- srigi
- Nette Blogger | 558
Tak som na to kapol. Nedoplo mi, ze ked sa komponent vytvara lazy, pocas renderovania stranky, uz je neskoro na redirect. Staci teda pripojenie komponenty presunut napr. do akcie:
public function actionDefault()
{
$this->addComponent(new VisualPaginator, 'paginator');
}
public function renderDefault()
{
$page = $this['paginator']->page;
$posts = $this->db->table('post')->where('published IS NOT NULL');
...
}
a zrusit tovarnicku. Kanonizacia sa rozbehne :) Sice uz nemam lazy
load komponenty, ale v mojom pripade mi to nevadi.
Editoval srigi (30. 1. 2013 22:14)