Ejemplo n.º 1
0
 /**
  * Creates url from a Date and Title
  * @param $date Date of article
  * @param $title Article title
  * 
  * @todo Extend this function for custom urls
  */
 private function getUrl($date, $slug)
 {
     $date = new DateTime($date);
     $date = $date->format('Y-m-d');
     $dateSplit = explode('-', $date);
     return $this->slim->urlFor('article', array('year' => $dateSplit[0], 'month' => $dateSplit[1], 'date' => $dateSplit[2], 'article' => $slug));
 }
Ejemplo n.º 2
0
 /**
  * Creates url from a Date and Title
  * @param $date Date of article
  * @param $title Article title
  * 
  * @todo Extend this function for custom urls
  */
 function getUrl($date, $title)
 {
     $slug = strtolower(trim($title));
     $find = array(' ', '&', '\\r\\n', '\\n', '+', ',');
     $slug = str_replace($find, '-', $slug);
     $date = new DateTime($date);
     $date = $date->format('Y-m-d');
     $dateSplit = explode('-', $date);
     return $this->slim->urlFor('article', array('year' => $dateSplit[0], 'month' => $dateSplit[1], 'date' => $dateSplit[2], 'article' => $slug));
 }
Ejemplo n.º 3
0
 /**
  * Test Slim URL For
  *
  * Pre-conditions:
  * You have initialized a Slim app with a named route.
  *
  * Post-conditions:
  * Slim returns an accurate URL for the named route.
  */
 public function testSlimUrlFor(){
     Slim::init();
     Slim::get('/hello/:name', function () {})->name('hello');
     $this->assertEquals('/hello/Josh', Slim::urlFor('hello', array('name' => 'Josh')));
 }
Ejemplo n.º 4
0
    echo '<p>Here are the details about your PUT request:</p>';
    print_r(Slim::request());
});
//Sample PUT route for PHP <5.3
/*
Slim::put('/put', 'put_example');
function put_example() {
	echo '<br/><br/>Here are the details about your PUT request:<br/><br/>';
	print_r(Slim::request());
}
*/
//Sample DELETE route for PHP >=5.3
Slim::delete('/delete', function () {
    echo '<p>Here are the details about your DELETE request:</p>';
    print_r(Slim::request());
});
//Sample DELETE route for PHP <5.3
/*
Slim::delete('/delete', 'delete_example');
function delete_example() {
	echo '<br/><br/>Here are the details about your DELETE request:<br/><br/>';
	print_r(Slim::request());
}
*/
/*** NAMED ROUTES *****/
Slim::get('/hello/:name', function ($name) {
    echo "<p>Hello, {$name}!</p>";
    echo "<p>This route using name \"Bob\" instead of \"{$name}\" would be: " . Slim::urlFor('hello', array('name' => 'Bob')) . '</p>';
})->name('hello')->conditions(array('name' => '\\w+'));
/*** RUN SLIM ***/
Slim::run();
Ejemplo n.º 5
0
ActiveRecord\Config::initialize(function ($cfg) {
    $cfg->set_model_directory('models');
    $cfg->set_connections(array('development' => 'mysql://*****:*****@127.0.0.1/test'));
});
$app = new Slim();
$app->get('/', function () use($app) {
    $data['tasks'] = Task::find('all');
    $app->render('task/index.php', $data);
})->name('tasks');
$app->post('/task/new/', function () use($app) {
    $task = new Task();
    $task->name = "My New Task";
    $task->done = 0;
    $task->save();
    if ($task->id > 0) {
        $app->redirect($app->urlFor('tasks'));
    }
})->name('task_new');
$app->get('/task/:id/edit', function ($id) use($app) {
    $data['task'] = Task::find($id);
    $app->render('task/edit.php', $data);
})->name('task_edit');
$app->post('/task/:id/edit', function ($id) use($app) {
    $task = Task::find($id);
    $task->name = $app->request()->post('name');
    $task->done = $app->request()->post('done') === '1' ? 1 : 0;
    $task->save();
    if ($task->id > 0) {
        $app->redirect($app->urlFor('tasks'));
    }
})->name('task_edit_post');
Ejemplo n.º 6
0
 /**
  * Test URL for
  */
 public function testSlimUrlFor()
 {
     $s = new Slim();
     $s->get('/hello/:name', function () {
     })->name('hello');
     $this->assertEquals('/foo/hello/Josh', $s->urlFor('hello', array('name' => 'Josh')));
     //<-- Prepends physical path!
 }
Ejemplo n.º 7
0
 public function urlFor($name, $params = array())
 {
     return sprintf('/%s%s', $this->view()->getLang(), parent::urlFor($name, $params));
 }
Ejemplo n.º 8
0
 /**
  * Test Slim URL For
  *
  * Pre-conditions:
  * Slim app instantiatd with named route;
  *
  * Post-conditions:
  * Slim returns an accurate URL for the named route;
  */
 public function testSlimUrlFor()
 {
     $app = new Slim();
     $app->get('/hello/:name', function () {
     })->name('hello');
     $this->assertEquals('/hello/Josh', $app->urlFor('hello', array('name' => 'Josh')));
 }
Ejemplo n.º 9
0
Archivo: index.php Proyecto: stojg/puny
 * @var Slim
 */
$app = new Slim(array('templates.path' => TEMPLATE_PATH));
/**
 * Add a middleware to all routes. Adding commonly accessed variables to the
 * view.
 */
$app->add(new puny\helpers\ViewHelper());
/** 
 * This is a Slim middleware route that prevents non logged in visitors to
 * access that route
 */
$locked = function () use($app) {
    return function () use($app) {
        if (!puny\User::is_logged_in()) {
            $app->redirect($app->urlFor('login'));
        }
    };
};
/**
 * This is the index page
 */
$app->get('/', function () use($app) {
    $posts = puny\Blog::get_posts(5);
    $app->render('home.php', array('posts' => $posts));
})->name('index');
/**
 * Show a single post
 */
$app->get('/blog/:url', function ($url) use($app) {
    $blog = new puny\Blog('posts/');