php簡單測試slim架構的功能

來源:互聯網
上載者:User
php簡單測試slim架構的功能

監聽主路徑/

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



Slim Framework for PHP 5






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'];
//<-- Should not be in response body!
// $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,用起來還是不錯的。

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.