コード例 #1
0
ファイル: Textpress.php プロジェクト: resmo/renemoser.net.old
 /**
  * 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));
 }
コード例 #2
0
ファイル: Textpress.php プロジェクト: nikhilben/TextPress
 /**
  * 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));
 }
コード例 #3
0
ファイル: SlimTest.php プロジェクト: ntdt/Slim
 /**
  * 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')));
 }
コード例 #4
0
ファイル: bootstrap.php プロジェクト: Jud/Slim
    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();
コード例 #5
0
ファイル: index.php プロジェクト: kxopa/slimactiverecord
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');
コード例 #6
0
ファイル: SlimTest.php プロジェクト: rs3d/Slimplr
 /**
  * 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!
 }
コード例 #7
0
 public function urlFor($name, $params = array())
 {
     return sprintf('/%s%s', $this->view()->getLang(), parent::urlFor($name, $params));
 }
コード例 #8
0
ファイル: SlimTest.php プロジェクト: inscriptionweb/lebonmail
 /**
  * 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')));
 }
コード例 #9
0
ファイル: index.php プロジェクト: 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/');