Beispiel #1
0
 public function listen()
 {
     $routing = new BaseRoute();
     $routing->get('/', ['controller' => 'main', 'action' => 'index']);
     $routing->get('/article', ['controller' => 'main', 'action' => 'article']);
     $routing->post('/admin/edit/news', ['controller' => 'admin', 'action' => 'editNews']);
     $routing->get('/admin/edit/news', ['controller' => 'admin', 'action' => 'editNews']);
     $routing->get('/admin/delete/news', ['controller' => 'admin', 'action' => 'deleteNews']);
     //тесты
     $routing->get('/test/each', function () {
         $model = \Models\News::find()->queryEach();
         foreach ($model as $root) {
             echo $root->id . "<br>";
         }
     });
     //так как учебный пример, можно и в роуте
     $routing->get('/admin/test', function () {
         $user = User::findOne('id = 1');
         $news = News::findOne('id = 1');
         $data = new AdminDataTable([$user, $news], [function ($model) {
             return $model->id + 1;
         }, function ($model) {
             if ($model->name) {
                 return $model->name;
             }
             return "(no name)";
         }]);
         echo $data->render();
     });
     $routing->listen();
 }