-
Notifications
You must be signed in to change notification settings - Fork 18
Development: DataFromPathHelper Component
Sami Mokaddem edited this page Jan 13, 2021
·
2 revisions
The DataFromPathHelper.php provides function to replace strings (or array of strings) with data extracted from a cakephp's utility Hash path
-
buildStringFromDataPath
Allows the creation of a string using raw value, datapath or a function
$url = $this->DataFromPath->buildStringFromDataPath(
'https://localhost/{{0}}/{{1}}.{{2}}',
['User' => ['id' => 42]],
[
['raw' => 'users/view'],
['datapath' => 'User.id'],
['function' => function($data, $dataPath) { return 'json'; }]
]
);
// 'https://localhost/users/view/42.json'
-
buildStringsInArray
AppliesbuildStringFromDataPath
for each elements in the provided array
$myArray = $this->DataFromPath->buildStringsInArray(
[
'string1' => __('Is this the {{0}} life?'),
'string2' => __('Is this {{0}} {{1}}?'),
],
['Queen' => ['text1' => 'real']],
[
'string1' => ['Queen.text1'],
'string2' => [
['raw' => 'just'],
[
'text' => 'fantasy',
'function' => function($data, $dataPath) { return $dataPath['text']; }
]
],
]
);
// [
// 'string1' => 'Is this the real life?',
// 'string2' => 'Is this just fantasy?',
// ]