Skip to content

Commit d18f724

Browse files
authored
Merge pull request #8066 from cakephp/issue-8064
Add example using splat operator with find()
2 parents 0678526 + e62d14a commit d18f724

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

en/orm/retrieving-data-and-resultsets.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ You can also provide many commonly used options to ``find()``::
145145
limit: 10
146146
);
147147

148+
If your finder options are in an array, you can use the `splat operator <https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list>`_ (``...``)
149+
to pass them into ``find()``::
150+
151+
$options = [
152+
'conditions' => ['Articles.created >' => new DateTime('-10 days')],
153+
'contain' => ['Authors', 'Comments'],
154+
'limit' => 10,
155+
]
156+
$query = $articles->find('all', ...$options);
157+
148158
The list of named arguments supported by find() by default are:
149159

150160
- ``conditions`` provide conditions for the WHERE clause of your query.
@@ -160,7 +170,7 @@ The list of named arguments supported by find() by default are:
160170
- ``join`` define additional custom joins.
161171
- ``order`` order the result set.
162172

163-
Any options that are not in this list will be passed to beforeFind listeners
173+
Any options that are not in this list will be passed to ``beforeFind`` listeners
164174
where they can be used to modify the query object. You can use the
165175
``getOptions()`` method on a query object to retrieve the options used. While
166176
you can pass query objects to your controllers, we recommend that you package

0 commit comments

Comments
 (0)