-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'nest' method to ArrayHelper #6
Comments
Thank you for putting effort in the improvement of the Yii framework. Unfortunately a use case is missing. It is required to get a better understanding of the pull request and helps us to determine the necessity and applicability of the suggested change to the framework. Could you supply us with a use case please? Please be as detailed as possible and show some code! Thanks! This is an automated comment, triggered by adding the label |
Here are some use cases:
|
Why aren't you iterating and outputting it right away? protected function renderComments($parentID = null, $i = 0)
{
$out = '';
foreach ($this->comments as $comment) {
if ($comment->parent_id === $parentID) {
$out .= $this->render('comment', [
'comment' => $comment, 'class' => $parentID !== null && $i !== 0 ? 'child-comment' : ''
]);
$i++;
$out .= $this->renderComments($comment->id, $i);
}
}
return $out;
}
OK, that one makes sense... |
No. |
@johonunu CakePHP releases their utility classes in a separate package; you could use that. |
@SamMousa I know that, I just wanted to note that it would be good idea to have it in the core. Most of the methods in Hash class are available inside ArrayHelper, but something like "nest" isn't. I can live without it in core, if I am the only one missing it ;) |
I think we would be nice to introduce method 'nest' similar to CakePHP one to ArrayHelper. It is used to create threaded data (with children nodes).
More information regarding it:
https://book.cakephp.org/3.0/en/core-libraries/hash.html#Cake\Utility\Hash::nest
https://github.com/cakephp/utility/blob/master/Hash.php#L1172
Is it possible to get same response using ArrayHelper::map somehow ?
The text was updated successfully, but these errors were encountered: