About adding data to cakephp3 object types

Asked 2 years ago, Updated 2 years ago, 43 views

How do I retrieve data repeatedly through find and add data?
It's a little hard to convey in writing, so I'm attaching an example below.
(The jquery's ajax returns JSON.)

$aaa is an object type [{...}, {...}] on the first storage, but
If you push array_push as shown below, it will be [{...}, {...}] [{...}, {...}, {...}].
How do I add things like [{...}, {...}, {...}, {...}, {...}]?
一The reason why we do this separately rather than all at once is because the data is huge and the memory is high.

// 1st time
$query=$this->Lists->find();
$lists = $query->limit(2)->offset(0);

$response=$this->response;  
$response->getBody()->write(json_encode($list1s)));

// Stored in variable
$aaa=$response;

// Second time
$list1s = $query->limit(3)->offset(2);
$response=$this->response;
$response->getBody()->write(json_encode($list1s)));

// Add data to variable
array_push($aaa,$response);

return$aa;

php cakephp

2022-09-30 16:37

1 Answers

I write json to lists→json encoding→response, so
If you do not read json from lists←json decode←response, it will make no sense.

If for some reason you can't adjust the process, take out what you need, as shown above.
If it's within one function, it's easiest to connect lists directly to each other.

By the way, the sample code is unnaturally listed or listed 1s, so
Let's see if there are any common mistakes.

Also, let's consider whether the name is appropriate in the lists.
This is a collection of lists, the nuance of a collection of collections,
will be


2022-09-30 16:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.