home.ctp
<?php
echo $this->element('distromob/featured');
?>
WebsitesController.php
<?php
class WebsitesController extends AppController {
public $components = array('Paginator');
public function index(){
$images = $this->paginate('Website');
if (isset($this->params['requested'])) {
return $images;
} else {
$this->set('images', $images);
}
}
featured.ctp
<?php
$images = $this->requestAction('/Websites/index');
?>
<ul>
<?php
foreach($images as $image): ?>
<?php $domain = $image['Website']['domain'];?>
<li><?php echo $this->Html->image('websites/' . $image['Website']['image'],array('width'=>'234px','height' =>'208px','class' => 'random'));
?>
</li>
<?php endforeach;?>
</ul>
<?php echo $this->Paginator->prev('« Previous', null, null, array('class' => 'disabled')); ?>
<?php $this->Paginator->counter(); ?>
<?php echo $this->Paginator->next('Next »', null, null, array('class' => 'disabled')); ?>
AppController.php
class AppController extends Controller {
public function beforeFilter(){
$this->Paginator->settings=array(
'limit'=>4
);
}
}
我是cakephp的新手我在网上发现了一些教程,但似乎不符合我的需要。我的问题是,为什么它是前一个和下一个分页数据不可点击,似乎分页数据基于我设置的限制
public function beforeFilter(){
$this->Paginator->settings=array(
'limit'=>4
);
}
每当我更改限制时,它也会显示数据,但我无法点击下一个和之前的
答案 0 :(得分:0)
尝试使用 - &gt; numbers()替换 - &gt; counter()以查看您是否有任何页码
答案 1 :(得分:0)
在元素中提供分页数据,即$ this-&gt; params [&#39; paging&#39;]
//index method
if ($this->params['requested'])
return array('images'=>$this->paginate('WebSite'), 'paging' => $this->params['paging']);
$this->set('images', $this->paginate('WebSite') );
然后在你的home.ctp做这个
$images = $this->requestAction(array('controller'=>'websites','action'=>'index'));
// if the 'paging' variable is populated, merge it with the already present paging variable in $this->params. This will make sure the PaginatorHelper works
if(!isset($this->params['paging'])) $this->params['paging'] = array();
$this->params['paging'] = Hash::merge( $this->params['paging'] , $images['paging'] );