Exemple #1
0
 public static function getInstance(array $config = array())
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
         self::$_instance->config = array('charset' => 'utf-8', 'content_type' => 'text/html', 'database' => array('models' => BASE_PATH . '/models/', 'engine' => 'sqlite3', 'db_name' => BASE_PATH . '/test.db'), 'static_url' => '/static', 'xhtml_tags' => false);
         Request::create();
     }
     date_default_timezone_set('Australia/ACT');
     return self::$_instance;
 }
Exemple #2
0
 public static function render($path, array $args = array())
 {
     if (self::$_instance === NULL) {
         self::init();
     }
     $args['request'] = Request::getInstance();
     $args['static_url'] = Rivet::getInstance()->config['static_url'];
     $template = self::$_instance->twig->loadTemplate($path);
     $template->routes = Routes::getInstance();
     self::$_instance->body = $template->render($args);
     return self::$_instance->body;
 }
Exemple #3
0
 public static function model($model_name, $parameters = array())
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
         self::$_instance->model = $model;
         // get pointer to config
         $config = Rivet::getInstance()->config;
         self::$_instance->db = new SQLite3($config['database']['db_name']);
         self::$_instance->modelPath = $config['database']['models'];
         self::$_instance->model_name = $model_name;
         self::$_instance->model = self::$_instance->newModelObject($model_name, $parameters);
         self::$_instance->query['from'] = strtolower(get_class(self::$_instance->model));
         self::$_instance->query['select'] = '*';
         self::$_instance->query['where'] = array();
     }
     return self::$_instance;
 }
Exemple #4
0
    }
    return Template::render('contacts/index.html', array('form' => $form, 'contacts' => DB::model('Contacts')->order_by('date', 'desc')->all()));
}), new Route('/contact', 'contact', function ($request) {
    $form = new Form(array(new TextField('name', array('required' => true), array('placeholder' => 'Your Name')), new EmailField('email', array('required' => true), array('placeholder' => 'Your Email')), new URLField('address', array('required' => false), array('placeholder' => 'http://')), new TextField('subject', array('required' => true), array('placeholder' => 'Subject')), new TextBoxField('message', array('required' => true))));
    $test = '"hello world..." My AMPS are really good-lookin\' & my type is clean!';
    if ($request['method'] == 'post') {
        echo $request['post']['message'] . "<br>";
        $form = $form($request['post']);
        if ($form->is_valid()) {
            echo $form['message'] . "<br>";
        }
    }
    return Template::render('contact/index.html', array('form' => $form, 'test' => $test));
}), new Route('/journal/{?int:page}', 'journal', function ($request, $page = 0) {
    return Template::render('journal/index.html', array('articles' => DB::model('Articles')->order_by('date', 'desc')->all()));
}), new Route('/journal/{slug:article}', 'article', function ($request, $article) {
    $article = DB::model('Articles')->where('slug', $article)->exec();
    return Template::render('journal/article.html', array('article' => $article[0], 'tags' => DB::model('Tag')->all()));
}), new Route('/journal/{slug:tag}', 'tag', function ($request, $tag) {
    return Template::render('journal/tag.html', array('tag' => $tag));
}), new Route('/foo', 'foo', function ($request) {
    return redirect(reverse('bar'));
}), new Route('/bar', 'bar', function ($request) {
    return 'You were redirected from Foo!';
}), new Route('/404', '404', function ($request) {
    return notfound();
}), new Route('/500', '500', function ($request) {
    return error();
})));
echo Rivet::dispatch();
Exemple #5
0
 public function render()
 {
     return sprintf($this->renderString, $this->name, $this->id, stripslashes($this->getValue()), $this->getAttrs(), Rivet::getInstance()->config['xhtml_tags'] ? '/' : '');
 }