本文整理汇总了PHP中Slim::contentType方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::contentType方法的具体用法?PHP Slim::contentType怎么用?PHP Slim::contentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim
的用法示例。
在下文中一共展示了Slim::contentType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testResponseContentTypeIsOverriddenToHtml
/**
* Test middleware overrides response content type to html
*/
public function testResponseContentTypeIsOverriddenToHtml()
{
Slim_Environment::mock(array('SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/foo'));
$app = new Slim(array('log.enabled' => false));
$app->get('/foo', function () use($app) {
$app->contentType('application/json;charset=utf-8');
//<-- set content type to something else
throw new Exception('Test Message', 100);
});
$mw = new Slim_Middleware_PrettyExceptions();
$mw->setApplication($app);
$mw->setNextMiddleware($app);
$mw->call();
$response = $app->response();
$this->assertEquals('text/html', $response['Content-Type']);
}
示例2: testSlimContentType
/**
* Test Slim::contentType
*
* Pre-conditions:
* You have initialized a Slim app and set the Content-Type
* HTTP response header.
*
* Post-conditions:
* The Response content type header is set correctly.
*/
public function testSlimContentType(){
Slim::init();
Slim::contentType('image/jpeg');
$this->assertEquals(Slim::response()->header('Content-Type'), 'image/jpeg');
}
示例3: Slim
<?php
require "Slim/Slim.php";
$app = new Slim();
$app->contentType('application/json');
//$app->post('/{lado1}/{lado2}/{lado3}', function($lado1, $lado2, $lado3) use($app) {
$app->post('/calcular', function () use($app) {
//$request = $app->request();
//$body = $request->getBody();
//$input = json_decode($body);
//$lado1 = $input->lado1;
//$lado2 = $input->lado2;
//$lado3 = $input->lado3;
//print_r();
$lado1 = $app->request()->params("lado1");
$lado2 = $app->request()->params("lado2");
$lado3 = $app->request()->params("lado3");
if ($lado1 <= 0 || $lado2 <= 0 || $lado3 <= 0) {
echo json_encode(array('status' => false, 'lado1' => $lado1, 'lado2' => $lado2, 'lado3' => $lado3, 'resultado' => "Lado menor ou igual a zero"));
} else {
if ($lado1 == $lado2 && $lado2 == $lado3) {
echo json_encode(array('status' => true, 'lado1' => $lado1, 'lado2' => $lado2, 'lado3' => $lado3, 'resultado' => "O triângulo é Equilátero"));
} else {
if ($lado1 == $lado2 || $lado2 == $lado3 || $lado3 == $lado1) {
echo json_encode(array('status' => true, 'lado1' => $lado1, 'lado2' => $lado2, 'lado3' => $lado3, 'resultado' => "O triângulo é Isósceles"));
} else {
echo json_encode(array('status' => true, 'lado1' => $lado1, 'lado2' => $lado2, 'lado3' => $lado3, 'resultado' => "O triângulo é Escaleno"));
}
}
}
});
示例4: testContentType
/**
* Test content type
*/
public function testContentType()
{
$s = new Slim();
$s->get('/bar', function () use($s) {
$s->contentType('application/json');
});
$s->call();
list($status, $header, $body) = $s->response()->finalize();
$this->assertEquals('application/json', $header['Content-Type']);
}
示例5: __construct
/**
* Constructor
*
* @param Slim $app
* @return void
*/
public function __construct(\Slim\Slim $app)
{
$this->app = $app;
$this->app->contentType('application/json');
$this->response = $this->app->response();
}
示例6: Autoloader
// https://github.com/briannesbitt/Slim-ContextSensitiveLoginLogout/blob/master/index.php
require "libs/autoloader.php";
//Autoload para as classes próprias
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'];
}
示例7: testSlimContentType
/**
* Test Slim::contentType
*
* Pre-conditions:
* Slim app instantiated;
* Content-Type header is set using helper method;
*
* Post-conditions:
* The Response content type header is set correctly;
*/
public function testSlimContentType()
{
$app = new Slim();
$app->contentType('image/jpeg');
$this->assertEquals('image/jpeg', $app->response()->header('Content-Type'));
}
示例8: testContentType
/**
* Test content type
*/
public function testContentType()
{
$s = new Slim();
$s->get('/bar', function () use($s) {
$s->contentType('application/json');
});
$env = $s->environment();
list($status, $header, $body) = $s->call($env);
$this->assertEquals('application/json', $header['Content-Type']);
}