0
votes

Controller Code:

public $paginate = [
        'fields' => ['Subscribes.id'],
        'limit' => 1,
        'order' => [
            'Subscribes.created' => 'desc'
        ]
    ];

Controller Method Code: Here $type is variable, value can be interger 1,2 3 etc

        $customFinderOptions = [
            'type' => $type
        ];

        $this->paginate = [
            'finder' => [
                'typed' => $customFinderOptions
            ]
        ];

        $contacts = $this->paginate($this->Subscribes);

Model Code:

public function findTyped(Query $query, array $options) {

        $type = $options['type'];
        return $query->where(['type' => $options['type']]);
    }

Error: As you can see limit is set to 1 but it returns all the records. Which means pagination is not working with custom finder method.

1

1 Answers

1
votes

It doesn't work, because you are overwriting your $paginate variable. Set it once in your controller action, use array_merge(), or update just single key:

$this->paginate["finder"] = [...];