Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

reworking the app/index.php example to make it a bit more robust and …

…useful
  • Loading branch information...
commit 6b7e167152a00a26d39d7a03d6c789765e45f82a 1 parent 6d43549
Chris Cornutt authored
Showing with 95 additions and 30 deletions.
  1. +95 −30 app/index.php
125 app/index.php
View
@@ -1,41 +1,106 @@
-<?php
-include_once '../Shield/Shield.php';
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title>Shield : A Security-Minded Microfrmaework</title>
+ <link type="text/css"
+ href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css"
+ rel="stylesheet" type="text/css" media="screen"
+ />
+ </head>
+ <body>
+ <div class="container">
+ <h1>Shield Framework Examples</h1>
+ <div class="navbar">
+ <div class="navbar-inner">
+ <div class="container">
+ <ul class="nav">
+ <li class="active"><a href="/">Home</a></li>
+ <li><a href="/filters?test=notvalid@email&test1=Me">Filtering</a></li>
+ <li><a href="/cfg">Custom Config</a></li>
+ </ul>
+ </div>
+ </div>
+ </div>
-$app = new Shield\Shield();
+ <br/>
+ <?php
+ include_once '../Shield/Shield.php';
-$app->get('/', function() use ($app){
+ $app = new Shield\Shield();
- /** Add some View values */
- $app->view->set('fake','<b>link text</b>');
- $app->view->set('test', 'foodles');
+ /**
+ * A basic route assigning values to the view
+ */
+ $app->get('/', function() use ($app){
- /** Add a filter of type "email" */
- $app->filter->add('test', 'email');
-
- /** Adding a filter with a closure **/
- $app->filter->add('test1', function($value){
- echo 'my value: '.$value; return $value;
+ $app->view->set(array(
+ 'fake' => '<b>link text</b>',
+ 'test' => 'foodles'
+ ));
+ return $app->view->render('
+ <h3>Basic Routing & Escaping</h3>
+ <p>
+ This route sets two values to the view "fake" & "test". The "fake"
+ value has HTML in it and is, by default, filtered.
+ </p>
+ <br/><b>Output</b><hr/>
+ index1: <a href="#[test]">[fake]</a>
+ ');
});
- /** GETs from the URL, "?test=foo"
- this will be empty because there's an "email" filter on it */
- echo "?test : {$app->input->get('test')}\n";
+ /**
+ * Setting up filters on data (desides the default)
+ */
+ $app->get('/filters', function() use ($app){
+
+ $app->view->set(array(
+ 'test' => $app->input->get('test'),
+ 'test1' => $app->input->get('test1')
+ ));
+
+ $app->filter->add(array(
+ 'test' => 'email',
+ 'test1' => function($value){
+ return 'custom filter: '.$value;
+ }
+ ));
+
+ return $app->view->render('
+ <h3>Built-in & Custom Filters</h3>
+ <p>
+ There are several built-in filtering types including "email", "integer" and "url"
+ to help you sanitize your data.<br/>
+ You can also add custom filters using PHP\'s closures.
+ </p>
+ <br/><b>Output</b><hr/>
+ TEST1: [test1]<br/>
+ TEST: [test]
+ ');
+ });
- /** GETs from the URL, "&test1=foo" */
- echo "&test1: {$app->input->get('test1')}\n";
+ /**
+ * Shows how to use a custom configuration with a route
+ * NOTE: This page is in an HTML template, so this XML won't render correctly
+ * (but you get the idea....)
+ */
+ $app->get('/cfg', function() use ($app){
- echo 'config: '; var_export($app->config->get('test.foo')); echo '<br/><br/>';
-
- /** Render the template output */
- return $app->view->render('index1: <a href="#[test]">[fake]</a><br/><br/>');
-});
+ $app->view->set('output','my output');
-/** Define a "/test" route */
-$app->get('/test', function(){
- echo 'This is the Test route';
-});
+ return $app->view->render('
+ <?xml version="1.0">
+ <test>
+ <value>[output]</value>
+ </test>
+ ');
+ }, array(
+ 'view.content-type' => 'text/xml'
+ ));
-echo "<pre>";
-$app->run();
-echo "</pre>";
+ /** Execute the application */
+ $app->run();
+ ?>
+ </div>
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.