php简单测试slim框架的功能

WBOY
发布: 2016-06-23 13:35:46
原创
1252 人浏览过

php简单测试slim框架的功能

监听主路径/

 

$app->get(
'/',
function () {
$template =



Slim Framework for PHP 5




Slim

Welcome to Slim!



Congratulations! Your Slim application is running. If this is
your first time using Slim, start with this "Hello World" Tutorial.



Get Started



  1. The application code is in index.php

  2. Read the online documentation

  3. Follow @slimphp on Twitter




Slim Framework Community

Support Forum and Knowledge Base



Visit the Slim support forum and knowledge base
to read announcements, chat with fellow Slim users, ask questions, help others, or show off your cool
Slim Framework apps.

Twitter



Follow @slimphp on Twitter to receive the very latest news
and updates about the framework.




Slim Framework Extras



Custom View classes for Smarty, Twig, Mustache, and other template
frameworks are available online in a separate repository.


Browse the Extras Repository





EOT;
echo $template;
}
);

测试接收路径

$app->get(
'/post',
function () {
echo 'This is a POST route';
}
);

输入http://localhost/lims/index.php/post路径

出现This is a POST route

测试display


$app->get('/bar', function (){
// echo $_SERVER['SCRIPT_NAME'];
// echo $_SERVER['PHP_SELF'];
// // $app->redirect($_SERVER['SCRIPT_NAME'].'/');

$view = new \Slim\View();
$prop1 = new \ReflectionProperty($view, 'data');
$prop1->setAccessible(true);
$prop1->setValue($view, new \Slim\Helper\Set(array('foo' => 'bar','ss'=>array('foo'=>'barsss'))));

$prop2 = new \ReflectionProperty($view, 'templatesDirectory');
$prop2->setAccessible(true);
$prop2->setValue($view, dirname(__FILE__) . '/tests/templates');

$view->display('test.php');
});

输入http://localhost/lims/index.php/bar

出现test output barsss

正常

测试redirect

$app->get('/bar', function (){

$app->redirect($_SERVER['SCRIPT_NAME'].'/');


});

出现主页面,正常,slim框架几百k,用起来还是不错的。

 

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板