search

Home  >  Q&A  >  body text

Setting request data - CakePHP 4

We have a CakePHP 3.x application that we have updated to the latest CakePHP 4.x. As part of this work, we also changed from PHP 7 to PHP 8.

While testing the application, we noticed that a feature had stopped working.

The application is a searchable database and integrated with Redis for caching. One of the functions means

For clarity, the reason we set up the request data this way is because the search is done via an ajax call. When the user initially enters the search criteria, the page has not reloaded yet, so the form fields appear to be populated correctly. This issue occurs when the page is reloaded. In this case we want to use them

P粉212971745P粉212971745300 days ago497

reply all(1)I'll reply

  • P粉722521204

    P粉7225212042024-03-27 00:28:36

    The function you are looking for is withData. Remember that the request object is immutable, so you need to assign the result of that function call back to the request object, e.g. with $this->setRequest($this->getRequest()->withData('f1' , 'foo')->withData('f3', 'bar')).

    reply
    0
  • Cancelreply