Keep query alive during execution of script

I have a query where I show a grid paginated given a filter made by the user, when I click on page 2 it disappears because I ask if($this->request->is(‘post’)), how can I assign this query to a session variable so that it doesn’t disappear when I change of page?
This is the code of the action in the controller:

    public function query($id = null)
    {
		$this->paginate = [
			'contain' => ['Enterprises', 'Affiliates'],
		];
		$contributions = [];
		if($this->request->is('post')) {
			$where = ['Contributions.enterprise_id' => $id];
			if(!empty($this->request->getData('cuil'))) $where += ['Affiliates.cuil' => $this->request->getData('cuil')];
			if(!empty($this->request->getData('period_since'))){
				if(empty($this->request->getData('period_until'))) $where += ['period' => $this->request->getData('period_since')];
				else $where += ['period >=' => $this->request->getData('period_since')];
			}
			if(!empty($this->request->getData('period_until'))) $where += ['period <=' => $this->request->getData('period_until')];
			if(!empty($this->request->getData('created_since'))) $where += ['created >=' => $this->request->getData('created_since')];
			if(!empty($this->request->getData('created_until'))) $where += ['created <=' => $this->request->getData('created_until')];
			$contributions = $this->paginate($this->Contributions->find('all')->where($where));
			$taxable_remuneration = $this->Contributions->find('all')->where($where)->func()->sum('taxable_remuneration');
			$this->set('taxable_remuneration', $taxable_remuneration);
			$taxable_remuneration = $this->Contributions->find('all')->where($where)->func()->sum('taxable_remuneration');
			$this->set('taxable_remuneration', $taxable_remuneration);
			$union_dues = $this->Contributions->find('all')->where($where)->func()->sum('union_dues');
			$this->set('union_dues', $union_dues);
			$worker_contribution = $this->Contributions->find('all')->where($where)->func()->sum('worker_contribution');
			$this->set('worker_contribution', $worker_contribution);
			$solidarity_aid_fund = $this->Contributions->find('all')->where($where)->func()->sum('solidarity_aid_fund');
			$this->set('solidarity_aid_fund', $solidarity_aid_fund);
		}
		$this->set(compact('contributions'));
		$this->set('id', $id);
    }

I would recommend you look into the Post/Redirect/Get Pattern to keep filters alive.
Basically you shouldn’t put filter values inside the session or inside POST data but instead everything filter/pagination related should be inside the query params (aka GET params)

With that the paginator will also keep those filters active even when changing pages.
This is also how the GitHub - CakeDC/search: Search Plugin for CakePHP handles it