daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Feb 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. $strings[] = \App\Models\Article::findAll();
  3.  
  4. $columns =
  5.     [
  6.         'id' => function ($model) {
  7.             return $model->id;
  8.         },
  9.         'title' => function ($model) {
  10.             return $model->title;
  11.         },
  12.         'content' => function ($model) {
  13.             return $model->content;
  14.         },
  15.         'author_id' => function ($model) {
  16.             return $model->author_id;
  17.         },
  18.     ];
  19.  
  20.  
  21. class AdminDataTable
  22. {
  23.     protected $strings;
  24.     protected $columns;
  25.     protected $view;
  26.  
  27.     public function __construct(array $strings, array $columns)
  28.     {
  29.         $this->view = new View;
  30.         $this->view->strings = $strings;
  31.         $this->view->columns = $columns;
  32.     }
  33.  
  34.     public function render()
  35.     {
  36.         $this->view->display(__DIR__ . '/view/admin_table.php');
  37.     }
  38.  
  39. }
  40.  
  41. $admin = new AdminDataTable($strings, $columns);
  42. $admin->render();
  43.  
  44.  
  45. <h2>Я подобие модуля?</h2>
  46. <h3>Все записи</h3>
  47. <table>
  48.     <tr>
  49.         <?php foreach ($this->columns as $name => $func) { ?>
  50.             <th><?= $name; ?></th>
  51.         <?php } ?>
  52.     </tr>
  53.     <?php foreach ($this->strings as $strings) { ?>
  54.         <tr>
  55.         <?php foreach ($strings as $string) { ?>
  56.             <?php foreach ($this->columns as $func) { ?>
  57.                 <td><?= $func($string) ?? 'empty_value'; ?></td>
  58.             <?php } ?>
  59.             </tr>
  60.         <?php } ?>
  61.     <?php } ?>
  62. </table>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top