0

Controller code:

     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'));
    }

From that code must understand that the code looks as that is required but at same time i can't navigate further i also require code to run so i keep that clear code also put together code that would work according to single page but code require that code must put together a cycle that goes to next story entry without changing page that i display ie index.php.

View Code:

<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>

Code written makes pagination appear on the view but doesn't work when i click paginator.

1 Answers1

0

That is possible follow code below to make that work.

    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'));
    }

Important factor that shows up is that we put limit to number of result to show up each instance.