当前位置: 首页>>代码示例>>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;未经允许,请勿转载。