Open illuminate3 opened 9 years ago
The example has this render as an example:
function renderNode($node) { if( $node->isLeaf() ) { return '<li>' . $node->name . '</li>'; } else { $html = '<li>' . $node->name; $html .= '<ul>'; foreach($node->children as $child) $html .= renderNode($child); $html .= '</ul>'; $html .= '</li>'; } return $html; }
But I'm having a huge problem converting this to a table set up .... (I'm using this as a presenter() )
public function renderTable($node) { $title = $node->title; if ($node->depth > 0) { $title = str_repeat('—', $node->depth) . ' ' . $title; } if ( $node->isLeaf() ) { $row = '<tr>'; $row .= '<td>' . $node->title . '/<td>'; $row .= '<td>' . $node->slug . '</td> <td> <a href="/admin/categories/' . $node->id . '/edit" class="btn btn-success" title="' . trans('kotoba::button.edit') . '"> <i class="fa fa-pencil fa-fw"></i> ' . trans('kotoba::button.edit') . ' </a> </td> '; $row .= '<tr>'; return $row; } else { $html = '<tr>'; $html .= '<td>' . $node->title . '/<td>'; $html .= '<td>' . $node->slug . '</td> <td> <a href="/admin/categories/' . $node->id . '/edit" class="btn btn-success" title="' . trans('kotoba::button.edit') . '"> <i class="fa fa-pencil fa-fw"></i> ' . trans('kotoba::button.edit') . ' </a> </td> '; $html .= '<tr>'; foreach($node->children as $child) { $html = $this->renderTable($child); } } return $html; }
I know it's dirty, I'm just trying to get it to work :frowning:
At the moment, the table is skipping the parent when a child is present.
I would really appreciate any help or comments :smile:
The example has this render as an example:
But I'm having a huge problem converting this to a table set up .... (I'm using this as a presenter() )
I know it's dirty, I'm just trying to get it to work :frowning:
At the moment, the table is skipping the parent when a child is present.
I would really appreciate any help or comments :smile: