0

controller code : code for controller works for Employers pagination but unable to work pagination about Stories controller.

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

    public function index()
    {
        // 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'));

    }

Model code: model description stand same for all model as yet but understand that model definition unable to work for stories model but as we progress with model definition about employers table that works absolutely fine.

<?php
// src/Model/Table/EmployersTable.php
namespace App\Model\Table;

use Cake\ORM\Table;

class EmployersTable extends Table
{
    public function initialize(array $config): void
    {
        $this->addBehavior('Timestamp');
    }
}

<?php
// src/Model/Entity/Employer.php
namespace App\Model\Entity;

use Cake\ORM\Entity;

class Spk extends Entity
{
    protected $_accessible = [
        '*' => true,
        'id' => false,
        'slug' => false,
    ];
}

<?php
// src/Model/Table/StoriesTable.php
namespace App\Model\Table;

use Cake\ORM\Table;

class StoriesTable extends Table
{
    public function initialize(array $config): void
    {
        $this->addBehavior('Timestamp');
    }
}

<?php

// src/Model/Entity/Story.php
namespace App\Model\Entity;

use Cake\ORM\Entity;

class Sty extends Entity
{
    protected $_accessible = [
        '*' => true,
        'id' => false,
        'slug' => false,
    ];
}

Bug i keep looking at as i get through load page action i face that Employers data called but Stories data unable to load. Suggestions are open to view look forward to your answers.

error message:

Undefined property: EmployersController::$Stories in /Applications/MAMP/htdocs/sd/sd/src/Controller/EmployersController.php
ndm
  • 59,784
  • 9
  • 71
  • 110

2 Answers2

0

Surely it's possible, the feature is explicitly documented. The error has nothing to do with pagination, it simply means that the property that you're trying access ($this->Stories) doesn't exist.

Controllers only have one default model that is being loaded automatically, and that's the model that matches the controller name according to the conventions, so in your EmployersController that's the Employers model. Additional models need to be loaded manually:

$this->loadModel('Stories');

// ...

$stories = $this->paginate($this->Stories, ['scope' => 'story']);

See also

ndm
  • 59,784
  • 9
  • 71
  • 110
0

No, That is not possible as CakePHP only works for single table with multiple pagination query request to same model. But doesn't not apply to many models.