donglin4636 2015-01-19 10:15
浏览 41
已采纳

为什么我无法在PHP中将整个输出打印到屏幕上?

I'm using Slim framework for my project. I've copied the Slim folder to my project directory.

No following is the code I'm having issue with :

PHP Code(requestdemo.php):

    <?php

    require 'Slim/Slim.php';

    /* Invoke the static "registerAutoloader()" function defined within Slim class. 
     * Register the autoloader is very important. 
     * Without doing it nothing will work.
    */ 
    \Slim\Slim::registerAutoloader();

    //Instantiate Slim class in order to get a reference for the object.
    $application = new \Slim\Slim();

    $application->get(
        '/request',
        function() 
        {
          GlOBAL $application;
          echo "&nbsp;<br/><b>request methods</b>";
          echo "<br/>application->request->getMethod()=".$application->request->getMethod();
          echo "<br/>application->request->isGet()=".$application->request->isGet();
          echo "<br/>application->request->isPost()=".$application->request->isPost();
          echo "<br/>application->request->isPut()=".$application->request->isPut();
          echo "<br/>application->request->isDelete()=".$application->request->isDelete();
          echo "<br/>application->request->isHead()=".$application->request->isHead();
          echo "<br/>application->request->isOptions()=".$application->request->isOptions();
          echo "<br/>application->request->isPatch()=".$application->request->isPatch();
          echo "<br/>application->request->isAjax()=".$application->request->isAjax();
          echo "<br/>&nbsp;<br/><b>request headers</b>";
          $headers = $application->request->headers;
          foreach($headers as $k=>$v)
          {
            echo "<br/>$k => $v";
          }
          echo "<br/>&nbsp;<br/><b>request body</b>";
          echo "<br/>body=".$application->request->getBody();
          echo "<br/>&nbsp;<br/><b>request variables</b>";
          echo "<br/>width=".$application->request->params('width');
          echo "<br/>height=".$application->request->params('height');
          echo "<br/>&nbsp;<br/><b>request get variables</b>";
          echo "<br/>width=".$application->request->get('width');
          echo "<br/>height=".$application->request->get('height');
          echo "<br/>&nbsp;<br/><b>request post variables</b>";
          echo "<br/>width=".$application->request->post('width');
          echo "<br/>height=".$application->request->post('height');
          echo "<br/>&nbsp;<br/><b>resource uri</b>";
/*From the below line I'm not able to see the output in a browser.*/
          echo "<br/>rootUri=".$application->request->getUri();
          echo "<br/>resourceUri=".$application->request->getResourceUri();
          echo "<br/>&nbsp;<br/><b>request ajax check</b>";
          echo "<br/>rootUri=".$application->request->isAjax();
          echo "<br/>resourceUri=".$application->request->getResourceUri();
          echo "<br/>&nbsp;<br/><b>request helpers</b>";
          echo "<br/>content type=".$application->request->getContentType();
          echo "<br/>media type=".$application->request->getMediaType();
          echo "<br/>host=".$application->request->getHost();
          echo "<br/>scheme=".$application->request->getScheme();
          echo "<br/>path=".$application->request->getPath();
          echo "<br/>url=".$application->request->getUrl();
          echo "<br/>user agent=".$application->request->getUserAgent();
        });
    $application->run();
?>

The file 'requestdemo.php' is present in the directory titled "slimsamples" at location /var/www/slimsamples

As I hit the URL 'http://localhost/slimsamples/requestdemo.php/request' I'm able to see only the part of output in a browser window. From where I'm not able to see the output I've commented in my code. I'm not able to see the output after line resource uri. See the screenshot for further understanding. Incomplete output. Not able to see text after the heading resource uri

Also there is no syntactical error in it then why it's happening I'm not understanding.

Can someone please find out the mistake I'm making here?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • doulv8162 2015-01-19 10:19
    关注

    Use: request->getUrl()

    (You used request->getUri())

    See http://dev.slimframework.com/phpdocs/classes/Slim.Http.Request.html#getUrl

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度