是否可以通过导航使分页作为每页的单个项目工作

is that possible to make pagination work as single item per page with navigation

控制器代码:

     public $paginate = [
        'Employers' => ['scope' => 'employer'],
        'Stories' => ['scope' => 'story',
                      'page' => 1,
                      'limit' => 1]
    ];

    public function index()
    {
        //load model
        $this->loadModel('Stories');

        // Paginate property
        $this->loadComponent('Paginator');

        // In a controller action
        $stories = $this->paginate($this->Stories, ['scope' => 'story']);
        $employers = $this->paginate($this->Employers, ['scope' => 'employer']);
        //pr($stories);
        $this->set(compact('employers', 'stories'));
    }

从该代码必须理解该代码看起来是必需的但同时我无法进一步导航我还需要代码到 运行 所以我保持清晰的代码也将代码放在一起根据单页工作,但代码要求代码必须放在一起进入下一个故事条目的循环,而不更改我显示的页面,即 index.php。

查看代码:

<div class="row">
<div class="large-8 columns" style="border-right: 1px solid #E3E5E8;">
<article>
    <?php
        foreach($stories as $story){

            echo '<hr><div class="row">
            <div class="large-6 columns">
            <p>'.$this->Html->image($story['image'].'.jpg', ['alt'=>'image for article']).'</p>
            </div>
            <div class="large-6 columns">
            <h5><a href="#">'.$story['title'].'</a></h5>
            <p>
            <span><i class="fi-torso"> By '.$story['creator'].' &nbsp;&nbsp;</i></span>
            <span><i class="fi-calendar"> '.$story['created'].' &nbsp;&nbsp;</i></span>

            </p>
            <p>'.$story['story'].'</p>
            </div>
            </div><hr>';
        }
    ?>

<ul class="pagination" role="navigation" aria-label="Pagination">
    <li class="disabled"><?php echo $this->Paginator->prev('  ' . __('previous')); ?></li>
    <!--<li class="current">1</li>
    <li><a href="#" aria-label="Page 2">2</a></li>
    <li><a href="#" aria-label="Page 3">3</a></li>
    <li><a href="#" aria-label="Page 4">4</a></li>-->
    <li><?php echo $this->Paginator->prev(' >> ' . __('next')); ?></li>
</ul>
</article>
</div>

编写的代码使分页显示在视图上,但在我单击分页器时不起作用。

可以按照下面的代码进行操作。

    public $paginate = [

        'Stories' => ['scope' => 'story',
                      'limit' => 1,
                      ]
    ];

    public function initialize(): void
    {
        parent::initialize();
        $this->loadComponent('Paginator');
    }

    public function index()
    {
        //load model
        $this->loadModel('Stories');
        $this->loadModel('Sectors');

        // Paginate property
        $this->loadComponent('Paginator');

        // In a controller action
        $employers = $this->Employers->find('all');
        $sectors = $this->Sectors->find('all');
        $stories = $this->paginate($this->Stories->find('all', ['scope' => 'story']));
        //pr($sectorsandcourses);
        $this->set(compact('employers', 'stories', 'sectors'));
    }

显示的重要因素是我们限制了每个实例显示的结果数量。