CodeIgniter Forums
beforeFind functions not working when paginating - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: beforeFind functions not working when paginating (/showthread.php?tid=83546)



beforeFind functions not working when paginating - mehmet - 09-30-2022

Blog page pagination query;

PHP Code:
$blogQuery model('Blogs');
$list $blogQuery->where('locale'$this->request->getLocale())->where('published_at IS NOT NULL',null,false)->orderBy('tarih','DESC')->paginate(16);
$pager $blogQuery->pager


If I don't add where values before the paging function, it doesn't run the beforeFind functions in the model.

Blog Model;
PHP Code:
class Blogs extends Model
{
    protected $DBGroup          'default';
    protected $table            'blogs';
    protected $primaryKey      'id';
    protected $useAutoIncrement true;
    protected $insertID        0;
    protected $returnType      = \App\Entities\Blogs::class;
    protected $useSoftDeletes  true;
    protected $protectFields    true;
    protected $allowedFields    = [];

    // Dates
    protected $useTimestamps true;
    protected $dateFormat    'datetime';
    protected $createdField  'created_at';
    protected $updatedField  'updated_at';
    protected $deletedField  'deleted_at';

    // Validation
    protected $validationRules      = [];
    protected $validationMessages  = [];
    protected $skipValidation      false;
    protected $cleanValidationRules true;

    // Callbacks
    protected $allowCallbacks true;
    protected $beforeFind    = ['Published','Locale'];


    public function Published($data){
        $this->where('published_at IS NOT NULL',null,false);
        return $data;
    }

    public function Locale($data){
        $request service('request');
        $this->where('locale',$request->getLocale());
        return $data;
    }