當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Slim::urlFor方法代碼示例

本文整理匯總了PHP中Slim::urlFor方法的典型用法代碼示例。如果您正苦於以下問題:PHP Slim::urlFor方法的具體用法?PHP Slim::urlFor怎麽用?PHP Slim::urlFor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Slim的用法示例。


在下文中一共展示了Slim::urlFor方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getUrl

 /**
  * 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));
 }
開發者ID:resmo,項目名稱:renemoser.net.old,代碼行數:14,代碼來源:Textpress.php

示例2: getUrl

 /**
  * 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));
 }
開發者ID:nikhilben,項目名稱:TextPress,代碼行數:17,代碼來源:Textpress.php

示例3: testSlimUrlFor

 /**
  * 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')));
 }
開發者ID:ntdt,項目名稱:Slim,代碼行數:14,代碼來源:SlimTest.php

示例4: print_r

    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();
開發者ID:Jud,項目名稱:Slim,代碼行數:31,代碼來源:bootstrap.php

示例5: Slim

ActiveRecord\Config::initialize(function ($cfg) {
    $cfg->set_model_directory('models');
    $cfg->set_connections(array('development' => 'mysql://test:test@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');
開發者ID:kxopa,項目名稱:slimactiverecord,代碼行數:31,代碼來源:index.php

示例6: testSlimUrlFor

 /**
  * 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!
 }
開發者ID:rs3d,項目名稱:Slimplr,代碼行數:11,代碼來源:SlimTest.php

示例7: urlFor

 public function urlFor($name, $params = array())
 {
     return sprintf('/%s%s', $this->view()->getLang(), parent::urlFor($name, $params));
 }
開發者ID:Groxot,項目名稱:Slim-Multilingual,代碼行數:4,代碼來源:MultilingualSlim.php

示例8: testSlimUrlFor

 /**
  * 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')));
 }
開發者ID:inscriptionweb,項目名稱:lebonmail,代碼行數:16,代碼來源:SlimTest.php

示例9: Slim

 * @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/');
開發者ID:stojg,項目名稱:puny,代碼行數:31,代碼來源:index.php


注:本文中的Slim::urlFor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。