Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $strings[] = \App\Models\Article::findAll();
- $columns =
- [
- 'id' => function ($model) {
- return $model->id;
- },
- 'title' => function ($model) {
- return $model->title;
- },
- 'content' => function ($model) {
- return $model->content;
- },
- 'author_id' => function ($model) {
- return $model->author_id;
- },
- ];
- class AdminDataTable
- {
- protected $strings;
- protected $columns;
- protected $view;
- public function __construct(array $strings, array $columns)
- {
- $this->view = new View;
- $this->view->strings = $strings;
- $this->view->columns = $columns;
- }
- public function render()
- {
- $this->view->display(__DIR__ . '/view/admin_table.php');
- }
- }
- $admin = new AdminDataTable($strings, $columns);
- $admin->render();
- <h2>Я подобие модуля?</h2>
- <h3>Все записи</h3>
- <table>
- <tr>
- <?php foreach ($this->columns as $name => $func) { ?>
- <th><?= $name; ?></th>
- <?php } ?>
- </tr>
- <?php foreach ($this->strings as $strings) { ?>
- <tr>
- <?php foreach ($strings as $string) { ?>
- <?php foreach ($this->columns as $func) { ?>
- <td><?= $func($string) ?? 'empty_value'; ?></td>
- <?php } ?>
- </tr>
- <?php } ?>
- <?php } ?>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement