This might sound like a silly question, but since Laravel doesn't ship with any 'providers' functionality I'm just wondering.
I'm having a nested-set model used to store categories. I'm rendering a simple HTML list for a single form to display the categories tree in my controller view.
So yeah, this particular function is responsible for that:
private function renderDifferentNode( Category $node )
{
$html = '<li' . (!$node->isLeaf() ? ' class="collapsed"' : '') . ' data-role="node">' . PHP_EOL;
$nodeClass = $this->active->id === $node->id ? 'active' : '';
$html .= '<div class="nodeItem' . $nodeClass . '" data-id="' . $node->id . '">' . PHP_EOL;
$html .= $node->name . '</div>' . PHP_EOL;
if ( !$node->isLeaf() )
{
$html .= '<ul>' . PHP_EOL;
foreach ( $node->children as $child )
{
$html .= $this->renderDifferentNode( $child );
}
$html .= '</ul>' . PHP_EOL;
}
$html .= '</li>' . PHP_EOL;
return $html;
}
At first, I thought that the model will be a good place for that. However, model is rather 'global' and I need to use the function in only one controller. I also need to store currently active item so in the end I consider this as a bad idea.
The controller would be the best place I think, however it will create some mess.
What do you guys think? A helper class for a single function only wouldn't be too much?
If the description isn't clear enough, post the comment with any questions.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire