本文整理汇总了PHP中Slim::flash方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::flash方法的具体用法?PHP Slim::flash怎么用?PHP Slim::flash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim
的用法示例。
在下文中一共展示了Slim::flash方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authuser
function authuser($role = 'member')
{
$user = User::fetchFromDatabaseSomehow();
if ($user->belongsToRole($role) === false) {
Slim::flash('error', 'Login required');
Slim::redirect('/login');
}
}
示例2: testSetFlashForNextRequest
public function testSetFlashForNextRequest()
{
$s = new Slim();
$s->get('/bar', function () use($s) {
$s->flash('info', 'bar');
});
$this->assertFalse(isset($_SESSION['slim.flash']));
$s->run();
$this->assertEquals('bar', $_SESSION['slim.flash']['info']);
}
示例3: Autoloader
require "libs/Simplepie/autoloader.php";
//Autoload para as Classes do SimplePie, para leitura de RSS
require "libs/Slim/Slim.php";
//Micro-framework Slim, para gerenciamento de rotas e alguns Helpers
include "app/funcoes.php";
//Funções próprias, como CSS, Javascript e Meta
include "app/config.php";
//Configurações gerais do sistema, através de Constantes.
date_default_timezone_set('America/Sao_Paulo');
$autoloader = new Autoloader();
$app = new Slim();
$app->contentType('text/html; charset=utf-8');
$app->add(new Slim_Middleware_SessionCookie(array('secret' => '98897qwer65465qwe9r79qw9e354as68dh56k6lks6df8g', 'expires' => '60 minutes')));
$authenticate = function ($app) {
return function () use($app) {
if (!isset($_SESSION['dehbora']['user'])) {
$_SESSION['dehbora']['urlRedirect'] = $app->request()->getPathInfo();
$app->flash('error', 'Você precisa se logar.');
$app->redirect(URL_BASE . '/inicial');
}
};
};
$app->hook('slim.before.dispatch', function () use($app) {
$user = null;
if (isset($_SESSION['dehbora']['user'])) {
$user = $_SESSION['dehbora']['user'];
}
$app->view()->setData('user', $user);
});
require_once "app/routes.php";
$app->run();
示例4: Slim
$app = new Slim(array('view' => new TwigView()));
////////////////////////////////////////////////////////////////////////////////
//--Routes--////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/* purpose: main page show normal fizbuz and the structure / forms for the rest of the roots.
*
*/
$app->get('/', function () use($app) {
$args = array('numbers' => getNumberArray(1, 100));
$app->render('index.twig', $args);
});
$app->get('/:num', function ($pNumber) use($app) {
$args = array('number' => new FizBuzNumber($pNumber));
$app->render('single.twig', $args);
});
//->conditions(array('num'=> 'd+'));
$app->get('/list/(:start-):end', function ($start = 1, $end) use($app) {
if ($start >= $end) {
$app->flash("error start has to be greater than end");
//--TODO--/ redirect to first page.
}
$args = array('start' => $start, 'end' => $end, 'numbers' => getNumberArray($start, $end));
$app->render('list.twig', $args);
});
/**
* Step 4: Run the Slim application
*
* This method should be called last. This is responsible for executing
* the Slim application using the settings and routes defined above.
*/
$app->run();
示例5: testSlimFlash
/**
* Slim Flash
*
* Pre-conditions:
* Slim app sets Flash message for next request;
*
* Post-conditions:
* Message is persisted to $_SESSION after app is run;
*/
public function testSlimFlash()
{
$app = new Slim();
$app->get('/', function () use($app) {
$app->flash('info', 'Foo');
});
$app->run();
$this->assertArrayHasKey('info', $_SESSION['flash']);
$this->assertEquals('Foo', $_SESSION['flash']['info']);
}