亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 45
粉絲 0
評論 0
訪問量 45971
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
處理mvc的控制器訪問與參數(shù)解析
咸魚老爺
原創(chuàng)
825人瀏覽過

處理mvc的控制器訪問與參數(shù)解析

創(chuàng)建控制器Start.php

  1. <?php
  2. namespace controllers;
  3. class Start
  4. {
  5. public static function int()
  6. {
  7. $pathinfo = array_filter(explode('/', $_SERVER['PATH_INFO']));
  8. //生成控制器
  9. $controller = __NAMESPACE__ . '\\' . ucfirst(array_shift($pathinfo)).'Controller';
  10. $action = array_shift($pathinfo);
  11. //將url中的參數(shù)解析出來
  12. $params = [];
  13. for ($i = 0; $i < count($pathinfo); $i += 2) {
  14. if (isset($pathinfo[$i + 1]))
  15. $params[$pathinfo[$i]] = $pathinfo[$i + 1];
  16. }
  17. echo call_user_func_array([(new $controller), $action], $params);
  18. }
  19. }

入口文件index.php

  1. <?php
  2. //入口文件
  3. use controllers\Start;
  4. require __DIR__.'/vendor/autoload.php';
  5. Start::int();

通過pactinfo訪問user控制器中的select方法;http://127.0.0.119/pdo/ifram/index.php/user/select
運行結(jié)果圖

使用curl發(fā)起請求

  1. <?php
  2. // https://api.apiopen.top/getJoke?page=1&count=5&type=video
  3. $ustring = 'https://api.apiopen.top/getJoke?';
  4. $page = 1;
  5. $count = 5;
  6. $type = 'video';
  7. $query = http_build_query(['page' => $page, 'count' => $count, 'type' => $type]);
  8. $url = $ustring . $query;
  9. // 發(fā)起一個http請求
  10. $api = curl($url);
  11. function curl($url)
  12. {
  13. $ch = curl_init();
  14. curl_setopt($ch, CURLOPT_URL, $url);
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  18. $api = curl_exec($ch);
  19. curl_close($ch);
  20. return $api;
  21. }
  22. ?>
  23. <!DOCTYPE html>
  24. <html lang="zh-CN">
  25. <head>
  26. <meta charset="UTF-8">
  27. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  28. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  29. <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
  30. <title>Document</title>
  31. </head>
  32. <body>
  33. <table>
  34. <thead>
  35. <tr>
  36. <th>id</th>
  37. <th>標題</th>
  38. <th>作者</th>
  39. </tr>
  40. </thead>
  41. <tbody>
  42. </tbody>
  43. </table>
  44. </body>
  45. <script>
  46. const api = <?= $api ?>;
  47. let str='';
  48. $.each(api.result,(k,i)=>{
  49. str += '<tr>';
  50. str += '<td>'+i['sid']+'</td>';
  51. str += '<td>'+i['text']+'</td>';
  52. str += '<td>'+i['name']+'</td>';
  53. str +='</tr>';
  54. })
  55. $('tbody').html(str);
  56. </script>
  57. </html>

批改老師:天蓬老師天蓬老師

批改狀態(tài):合格

老師批語:
本博文版權(quán)歸博主所有,轉(zhuǎn)載請注明地址!如有侵權(quán)、違法,請聯(lián)系admin@php.cn舉報處理!
全部評論 文明上網(wǎng)理性發(fā)言,請遵守新聞評論服務(wù)協(xié)議
0條評論
作者最新博文
關(guān)于我們 免責(zé)申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長!
關(guān)注服務(wù)號 技術(shù)交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學(xué)習(xí)!
    全站2000+教程免費學(xué)