Paginator ve vlastnim controlu
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- neznalek
- Člen | 60
Ahoj rad bych definovat visual paginator ve vlastnim controletu vypisujici inzeraty:
<?php
public function renderSmall() {
$this->template->registerHelper('timeAgoInWords', 'Helpers::timeAgoInWords');
$vp = new VisualPaginator($this, 'vp');
$paginator = $vp->getPaginator();
$paginator->itemsPerPage = 3;
$this->demand->paginator($paginator->itemsPerPage, $paginator->offset);
$paginator->itemCount = count($this->demand);
$this->template->setFile(dirname(__FILE__) . '/template/small.phtml');
$this->template->items = $this->demand;
$this->template->render();
}
?>
Problem je ten ze promenna jine stranky ma tvar: demand-vp-page
a paginator uz si nedokaze upravit z teto promenne hodnotu.
Nevite prosim jak toto upravit? Dekuji
Editoval neznalek (6. 5. 2011 21:50)
- neznalek
- Člen | 60
No dival jsem se na zivotni cyklus ale nejak nevim ceho se chytnout.. Jak ho registuju moc pozde?
- Filip Procházka
- Moderator | 4668
Buď v akci nebo v továrničce, v render je pozdě. Přečti si to znovu.
- neznalek
- Člen | 60
Ale tovarnicku stejne musim volat v renderu..
Tak jsem zkusil akci v controleru
<?php
class DemandList extends Control {
protected $demand;
public function __construct(Nette\ComponentModel\IContainer $parent = NULL, $name = NULL) {
parent::__construct($parent, $name);
$this->demand = new Demand();
}
public function actionDefault() {
$vp = new VisualPaginator($this, 'vp');
$paginator = $vp->getPaginator();
$paginator->itemsPerPage = 2;
$this->demand->paginator($paginator->itemsPerPage, $paginator->offset);
$paginator->itemCount = count($this->demand);
}
public function renderSmall() {
$this->template->registerHelper('timeAgoInWords', 'Helpers::timeAgoInWords');
$this->template->setFile(dirname(__FILE__) . '/template/small.phtml');
$this->template->items = $this->demand;
$this->template->render();
}
?>
Sablona
<div class="demandListSmall">
<div class="item" n:foreach="$items as $i">
<span class="added">{$i->added|timeAgoInWords}</span>
<span class="category">{$i->category}</span>
{$i->title}
</div>
</div>
{control vp}
To mi hlasi: Component with name ‚vp‘ does not exist.
Editoval neznalek (18. 5. 2011 18:08)
- Majkl578
- Moderator | 1364
Komponenty nemají action fázi.
Zkus vyjít z tohohle:
<?php
class DemandList extends Control
{
protected $demand;
public function __construct(Nette\ComponentModel\IContainer $parent = NULL, $name = NULL)
{
parent::__construct($parent, $name);
$this->demand = new Demand();
}
public function renderSmall()
{
$this->template->registerHelper('timeAgoInWords', 'Helpers::timeAgoInWords');
$paginator = $this['vp']->getPaginator();
$paginator->itemsPerPage = 2;
$this->demand->paginator($paginator->itemsPerPage, $paginator->offset);
$paginator->itemCount = count($this->demand);
$this->template->setFile(dirname(__FILE__) . '/template/small.phtml');
$this->template->items = $this->demand;
$this->template->render();
}
protected function createComponentVp($name)
{
new VisualPaginator($this, $name);
}
}