php简单测试slim框架的功能
监听主路径/
$app->get(
'/',
function () {
$template =
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
- The application code is in
index.php
- Read the online documentation
- 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.
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.
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,用起来还是不错的。
上一篇: fgetcvs在linux的问题_PHP
推荐阅读
-
php简单实现短网址(短链)还原的方法(测试可用)
-
深入解析PHP的Yii框架中的缓存功能
-
全面解读PHP的Yii框架中的日志功能
-
详解PHP的Yii框架的运行机制及其路由功能
-
解析PHP的Yii框架中cookie和session功能的相关操作
-
PHP 实现超简单的SESSION与COOKIE登录验证功能示例
-
在Mac OS上搭建PHP的Yii框架及相关测试环境
-
php 实现简单的登录功能示例【基于thinkPHP框架】
-
JS实现的简单图片切换功能示例【测试可用】
-
EpiiAdmin 开源的php交互性管理后台框架, 让复杂的交互变得更简单!Phper快速搭建交互性平台的开发框架,基于Thinkphp5.1+Adminlte3.0+Require.js。