Output problem
Imagine Breaker
Imagine Breaker 2018-09-06 19:03:16
0
6
1656

Why can’t you dump ($result->getData()) directly after $result = Staff::select($where) instead of traversing the array foreach ($result as $value)

Imagine Breaker
Imagine Breaker

reply all(3)
jesse

Let’s take an official screenshot first to confirm the correctness of my underlying source code analysis:

QQ截图20180907224207.png

  • reply How did you send the screenshot and how did you operate it? Also, doesn’t it say in the video that select and all return an array of model objects?
    Imagine Breaker author 2018-09-08 09:35:52
  • reply Okay, I understand, sorry for the reverse, thank you! But how did you insert the picture? I didn’t see the option to insert pictures.
    Imagine Breaker author 2018-09-08 09:40:13
jesse

There are still several aspects to be discussed about this issue:

1. Since the data exists in the data attribute, how to determine the data attribute and remove the data set when traversing the object

2. This is just a Model object. If it is a Collection object, how is it implemented?

ArrayAccess should appear when these two problems arise. I will update it when I go back in the evening, so that you can truly understand the underlying operating mechanism of object traversal.

jesse

First read the official manual instructions:

QQ截图20180907141025.jpg

Then look at the underlying source code:

QQ截图20180907141312.jpg

QQ截图20180907141700.jpg

QQ图片20180907141926.png

QQ截图20180907142024.jpg

QQ截图20180907142220.jpg

##The official manual blocks many details and directly explains the results

QQ截图20180907142316.jpg

The last question, why can the returned results be traversed?

QQ截图20180907142514.jpg

QQ截图20180907142446.jpg

Both the Model class and the Collection class implement the same ArrayAccess interface, so that they can be accessed like an array properties in the object.

  • reply Because the returned result set is an object, the values ​​of the internal attributes must be obtained through array traversal. The data attribute is the result set of the database query.
    jesse author 2018-09-07 14:31:41
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template