Example #1
0
 public function actionUpdate($id = null)
 {
     $site = Site::findOneById($id);
     // I need some form of post checking
     if (Input::$method === 'post') {
         try {
             $success = false;
             $site->host = Input::post('site.host');
             $site->theme = Input::post('site.theme');
             $site->active = (bool) Input::post('site.active', false);
             $site->maintaining = (bool) Input::post('site.maintaining', false);
             $site->description = Input::post('site.description');
             if ($site->hasErrors()) {
                 throw new \OutOfBoundsException('');
             }
             // Attempt database write.
             list($success, $count) = $site->update();
             // If database wrote and actually added a record.
             if ($success and $count > 0) {
                 $this->flash->set('success', 'Successfully updated your site.');
                 $this->application->redirect(Url::site('/sites'));
             } else {
                 $this->flash->set('warning', 'There were no changes to save.');
             }
         } catch (\Nerd\DB\Exception $e) {
             $this->flash->set('error', 'There was a database error...');
         } catch (\OutOfBoundsException $e) {
             $form = $site->form($this->form())->action(Url::site("/sites/update/{$id}"));
             foreach ($site->errors as $field => $errors) {
                 $form->findByAttribute('id', "site_{$field}")->wrap('<div class="control-group error">', '</div>');
             }
             $this->flash->set('error', $site->errors);
         }
     }
     if (!isset($form)) {
         $form = $site->form($this->form())->action(Url::site("/sites/update/{$id}"));
     }
     $form->container('div', new Reset(['class' => 'btn']), new Submit(['class' => 'btn']))->class('form-actions');
     return $this->template->partial('content', 'sites/update', ['form' => $form, 'site' => $site]);
 }
Example #2
0
 public function actionUpdate($id = null)
 {
     $page = Page::findOneById($id);
     // I need some form of post checking
     if (Input::$method === 'post') {
         try {
             $success = false;
             $page->site_id = (int) Input::post('page.site_id');
             $page->layout_id = Input::post('page.layout_id');
             $page->title = Input::post('page.title');
             $page->subtitle = Input::post('page.subtitle');
             $page->description = Input::post('page.description');
             $page->status = Input::post('page.status');
             $page->priority = Input::post('page.priority');
             $page->change_frequency = Input::post('page.change_frequency');
             $uri = Input::post('page.uri') and $page->uri = $uri;
             if ($page->hasErrors()) {
                 throw new \OutOfBoundsException('');
             }
             list($success, $count) = $page->update();
             if ($success and $count > 0) {
                 $this->flash->set('success', "Successfully updated <em>{$page->title}</em>.");
                 $this->application->redirect(Url::site("/pages/view/{$id}"));
             } else {
                 $this->flash->set('warning', "No changes were made to <em>{$page->title}</em>.");
                 $this->application->redirect(Url::site('/pages'));
             }
         } catch (\Nerd\DB\Exception $e) {
             $this->flash->set('error', 'There was a database error...');
         } catch (\OutOfBoundsException $e) {
             $form = $page->form($this->form())->action(Url::site("/pages/update/{$id}"));
             foreach ($page->errors as $field => $errors) {
                 $form->findByAttribute('id', "page_{$field}")->wrap('<div class="control-group error">', '</div>');
             }
             $this->flash->set('error', $page->errors);
         }
     }
     if (!isset($form)) {
         $form = $page->form($this->form())->action(Url::site("/pages/update/{$id}"));
     }
     $form->container('div', new Reset(['class' => 'btn btn-danger']), new Submit(['class' => 'btn btn-primary']))->class('form-actions');
     return $this->template->partial('content', 'pages/update', ['form' => $form, 'page' => $page]);
 }
Example #3
0
<?php

namespace Application;

$app = Application::instance();
return ['application.startup' => function () use(&$app) {
    $app->session->referer = \Nerd\Input::server('HTTP_REFERER');
}, 'application.shutdown' => function () use(&$app) {
    $app->session->__destruct();
    if (isset($_GET['timer'])) {
        echo '<!-- ' . round(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], 6) . ' -->';
    }
}, 'application.error' => function () use(&$app) {
    // Pass and exception by default.
}, 'application.exception' => function () use(&$app) {
}];
Example #4
0
<?php

namespace Application;

use Nerd\Design\Architectural\MVC\Controller;
use Nerd\Design\Architectural\MVC\View;
use Nerd\Input;
return ['controller.setup' => function (Controller $controller) {
    $session = Application::instance()->session;
    if (!Input::protect($session->get('application.csrf'))) {
        throw new \Nerd\Http\Exception(403);
    }
    $controller->application = Application::instance();
    $controller->session = $session;
    $controller->flash = $session->flash;
    $controller->response = Application::instance()->response;
    $controller->template = new View('template');
}];