Skip to content

Improvement of documentation for Table::find() and Table::get() #8064

@nook24

Description

@nook24

With the new named parameters for Table::find() and Table::get() it is no longer possible, to pass variable options like so:

$args = [
    'contain' => [
        'Users'
    ],
    'where' => [
        'current_state >' => 1
    ]
];

if($user){
    $args['where']['Users.id'] = $user->get('id');
}

$query = $this->find('all', $args);

This can be worked around by using the Splat Operator (...)

$query = $this->find('all', ...$args);

I used this in my port of the ACL-Plugin as an quick and dirty fix: https://github.com/openITCOCKPIT/acl/blob/45dd93adb4dd917997561aec7b91281553128253/src/Model/Table/AclNodesTable.php#L67-L104

Maybe it's just me but even if this operator got introduced with PHP 5.6, it took me a few seconds before thinking of it. A hint and example in the docs would be good I guess.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions