zoukankan      html  css  js  c++  java
  • php简单测试slim框架的功能

    php简单测试slim框架的功能

    监听主路径/

    $app->get(
    '/',
    function () {
    $template = <<<EOT
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8"/>
    <title>Slim Framework for PHP 5</title>
    <style>
    html,body,div,span,object,iframe,
    h1,h2,h3,h4,h5,h6,p,blockquote,pre,
    abbr,address,cite,code,
    del,dfn,em,img,ins,kbd,q,samp,
    small,strong,sub,sup,var,
    b,i,
    dl,dt,dd,ol,ul,li,
    fieldset,form,label,legend,
    table,caption,tbody,tfoot,thead,tr,th,td,
    article,aside,canvas,details,figcaption,figure,
    footer,header,hgroup,menu,nav,section,summary,
    time,mark,audio,video{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent;}
    body{line-height:1;}
    article,aside,details,figcaption,figure,
    footer,header,hgroup,menu,nav,section{display:block;}
    nav ul{list-style:none;}
    blockquote,q{quotes:none;}
    blockquote:before,blockquote:after,
    q:before,q:after{content:'';content:none;}
    a{margin:0;padding:0;font-size:100%;vertical-align:baseline;background:transparent;}
    ins{background-color:#ff9;color:#000;text-decoration:none;}
    mark{background-color:#ff9;color:#000;font-style:italic;font-weight:bold;}
    del{text-decoration:line-through;}
    abbr[title],dfn[title]{border-bottom:1px dotted;cursor:help;}
    table{border-collapse:collapse;border-spacing:0;}
    hr{display:block;height:1px;border:0;border-top:1px solid #cccccc;margin:1em 0;padding:0;}
    input,select{vertical-align:middle;}
    html{ background: #EDEDED; height: 100%; }
    body{background:#FFF;margin:0 auto;min-height:100%;padding:0 30px;440px;color:#666;font:14px/23px Arial,Verdana,sans-serif;}
    h1,h2,h3,p,ul,ol,form,section{margin:0 0 20px 0;}
    h1{color:#333;font-size:20px;}
    h2,h3{color:#333;font-size:14px;}
    h3{margin:0;font-size:12px;font-weight:bold;}
    ul,ol{list-style-position:inside;color:#999;}
    ul{list-style-type:square;}
    code,kbd{background:#EEE;border:1px solid #DDD;border:1px solid #DDD;border-radius:4px;-moz-border-radius:4px;-webkit-border-radius:4px;padding:0 4px;color:#666;font-size:12px;}
    pre{background:#EEE;border:1px solid #DDD;border-radius:4px;-moz-border-radius:4px;-webkit-border-radius:4px;padding:5px 10px;color:#666;font-size:12px;}
    pre code{background:transparent;border:none;padding:0;}
    a{color:#70a23e;}
    header{padding: 30px 0;text-align:center;}
    </style>
    </head>
    <body>
    <header>
    <a href="http://www.slimframework.com"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHIAAAA6CAYAAABs1g18AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABRhJREFUeNrsXY+VsjAMR98twAo6Ao4gI+gIOIKOgCPICDoCjCAjXFdgha+5C3dcv/QfFB5i8h5PD21Bfk3yS9L2VpGnlGW5kS9wJMTHNRxpmjYRy6SycgRvL18OeMQOTYQ8HvIoJKiiz43hgHkq1zvK/h6e/TyJQXeV/VyWBOSHA4C5RvtMAiCc4ZB9FPjgRI8+YuKcrySO515a1hoAY3nc4G2AH52BZsn+MjaAEwIJICKAIR889HljMCcyrR0QE4v/q/BVBQva7Q1tAczG18+x+PvIswHEAslLbfGrMZKiXEOMAMy6LwlisQCJLPFMfKdBtli5dIihRyH7A627Iaiq5sJ1ThP9xoIgSdWSNVIHYmrTQgOgRyRNqm/M5PnrFFopr3F6B41cd8whRUSufUBU5EL4U93AYRnIWimCIiSI1wAaAZpJ9bPnxx8eyI3Gt4QybwWa6T/BvbQECUMQFkhd3jSkPFgrxwcynuBaNT/u6eJIlbGOBWSNIUDFEIwPZFAtBfYrfeIOSRSXuUYCsprCXwUIZWYnmEhJFMIocMDWjn206c2EsGLCJd42aWSyBNMnHxLEq7niMrY2qyDbQUbqrrTbwUPtxN1ZZCitQV4ZSd6DyoxhmRD6OFjuRUS/KdLGRHYowJZaqYgjt9Lchmi3QYA/cXBsHK6VfWNR5jgA1DLhwfFe4HqfODBpINEECCLO47LT/+HSvSd/OCOgQ8qE0DbHQUBq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>
    Congratulations! Your Slim application is running. If this is
    your first time using Slim, start with this <a href="http://docs.slimframework.com/#Hello-World" target="_blank">"Hello World" Tutorial</a>.
    </p>
    <section>
    <h2>Get Started</h2>
    <ol>
    <li>The application code is in <code>index.php</code></li>
    <li>Read the <a href="http://docs.slimframework.com/" target="_blank">online documentation</a></li>
    <li>Follow <a href="http://www.twitter.com/slimphp" target="_blank">@slimphp</a> on Twitter</li>
    </ol>
    </section>
    <section>
    <h2>Slim Framework Community</h2>

    <h3>Support Forum and Knowledge Base</h3>
    <p>
    Visit the <a href="http://help.slimframework.com" target="_blank">Slim support forum and knowledge base</a>
    to read announcements, chat with fellow Slim users, ask questions, help others, or show off your cool
    Slim Framework apps.
    </p>

    <h3>Twitter</h3>
    <p>
    Follow <a href="http://www.twitter.com/slimphp" target="_blank">@slimphp</a> on Twitter to receive the very latest news
    and updates about the framework.
    </p>
    </section>
    <section style="padding-bottom: 20px">
    <h2>Slim Framework Extras</h2>
    <p>
    Custom View classes for Smarty, Twig, Mustache, and other template
    frameworks are available online in a separate repository.
    </p>
    <p><a href="https://github.com/codeguy/Slim-Extras" target="_blank">Browse the Extras Repository</a></p>
    </section>
    </body>
    </html>
    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 SlimView();
    $prop1 = new ReflectionProperty($view, 'data');
    $prop1->setAccessible(true);
    $prop1->setValue($view, new SlimHelperSet(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,用起来还是不错的。

     代码地址http://pan.baidu.com/s/1bnpTY71

  • 相关阅读:
    java web项目打包.war格式
    version 1.4.2-04 of the jvm is not suitable for thi
    Sugarcrm Email Integration
    sharepoint 2010 masterpage中必须的Content PlaceHolder
    微信开放平台
    Plan for caching and performance in SharePoint Server 2013
    使用自定义任务审批字段创建 SharePoint 顺序工作流
    Technical diagrams for SharePoint 2013
    To get TaskID's Integer ID value from the GUID in SharePoint workflow
    how to get sharepoint lookup value
  • 原文地址:https://www.cnblogs.com/liuwenbohhh/p/4463180.html
Copyright © 2011-2022 走看看