hjrshng
hjrshng

Reputation: 1826

How to use an object method with Hash::map()?

How can i scope the function in Hash::map()?

Example:

$users = $this->User->find('all');
$results = Hash::map($users, '{n}', 'foo');

Where foo should be called as $this->foo.

http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html

Thanks.

Upvotes: 0

Views: 949

Answers (1)

ndm
ndm

Reputation: 60453

You do so by passing an array where the first entry points to the object, and the second one holds the method name: array($this, 'foo')

Hash::map($users, '{n}', array($this, 'foo'));

See also http://php.net/manual/en/language.types.callable.php

Upvotes: 2

Related Questions