Example #1
0
 public static function __initialize()
 {
     $app = static::instance();
     $uri = Url::current()->uri();
     $css = ['css/bootstrap.css', 'css/bootstrap-responsive.css'];
     $js = ['js/jquery.js', 'js/bootstrap.js'];
     $app->response = Response::instance();
     $app->session = Session::instance();
     $app->cache = Datastore::instance();
     $app->css = Asset::collection($css);
     $app->js = Asset::collection($js);
     // If there is no url, then we're on the home page.
     trim($uri, '/') == '' and $uri = '@@HOME';
     if ($page = Model\Page::findOneByUri($uri)) {
         $app->response->setBody($page->title);
         return;
     }
     try {
         Controller::instance()->dispatch($uri, $app->response);
         return;
     } catch (HttpException $e) {
         if (!($page = Model\Page::findOneByUri($uri = '@@404'))) {
             // Fallback to system handling.
             throw new HttpException(404, 'Page Not Found');
         }
         $app->response->setStatus(404);
         $app->response->setBody($page->title);
         return;
     }
 }
Example #2
0
 public function actionModelform()
 {
     \Nerd\Form\Label::defaultAttribute('class', 'control-label');
     $form = (new \Nerd\Form())->class('form-horizontal')->wrap('<div class="control-group">', '</div>')->wrapFields('<div class="controls">', '</div>');
     //$form = \Application\Model\State::findOneByCode('NJ')->form();
     \Application\Model\Page::findOne('SELECT * FROM nerd_pages')->form($form);
     return (new View('template'))->partial('content', 'test/form', ['form' => $form]);
 }
Example #3
0
 public function actionDelete($id = null)
 {
     try {
         $page = Page::findOneById($id);
         list($success, $count) = $page->delete();
     } catch (\Nerd\DB\Exception $e) {
         $this->flash->set('warning', "You may not delete <em>{$page->title}</em>. It is a <strong>Nerd</strong> protected file.");
         $this->application->redirect(Url::site('/pages'));
     }
     if ($success and $count > 0) {
         $this->flash->set('success', "<em>{$page->title}</em> has been deleted.");
     } else {
         $this->flash->set('error', "<em>{$page->title}</em> could not be deleted.");
     }
     $this->application->redirect(Url::site('/pages'));
 }