【问题标题】:Dont know how to load page dynamically with Swoole不知道如何使用 Swoole 动态加载页面
【发布时间】:2021-01-13 00:12:30
【问题描述】:

开发者朋友你好。

我正在尝试使旧网站与 swolle http 服务器一起使用,但我正在堆叠。 我按照入门教程进行操作,但找不到前进的方向。

<?php
use Swoole\Http\Server;
use Swoole\Http\Request;
use Swoole\Http\Response;

$server = new Swoole\HTTP\Server("127.0.0.1", 9501);

$server->on("start", function (Server $server) {
    echo "Swoole http server is started at http://127.0.0.1:9501\n";
});

$server->on("request", function (Request $request, Response $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

$server->start();

现在我想根据 url 动态加载我的内容(就像我使用 apache 服务器所做的那样),但找不到如何执行此操作。 这是我的旧索引文件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href="images/logo.png" type="image/x-icon">
    <link rel='stylesheet' type='text/css' href='css/bootstrap.min.css' />
    <link rel='stylesheet' type='text/css' href='css/jquery-ui.css' />
    <link rel='stylesheet' type='text/css' href='css/font-awesome.min.css' />
    <link rel='stylesheet' type='text/css' href='css/bootstrap-select.min.css' />
    <link rel='stylesheet' type='text/css' href='css/select2.css' />
    <link rel='stylesheet' type='text/css' href='css/admin.css' />
    <script src='js/jquery-3.1.1.min.js'></script>
    <script src="js/fusioncharts.js"></script>
    <script src="js/fusioncharts.charts.js"></script>
    <script src="js/fusioncharts.theme.fusion.js"></script>
</head>
<body >
    <?php
        if(in_array($_GET['_page'],array('connexion','deconnexion')))
            require_once('vues/'.$_GET['_page'].'.php');
        else
        {
            require_once('vues/header.php');
            echo'<div class="container clearfix">
                    <div class="col-sm-2"><div class="menu-gauche">'; require_once('vues/menu.php');echo'</div></div>
                    <div class="col-sm-9 menu-droite">';
                    if(!isset($_GET['_act'])&&!in_array($_GET['_page'],array('accueil','compte','profil')))
                        include('vues/filtre.php');
                    require_once('vues/'.$_GET['_page'].'.php');
            echo'   </div>
                </div><div class="clearfix"></div>';
                require_once('vues/footer.php');
        }
    ?>
    <script src='js/mask-js.js'></script>
    <script src='js/bootstrap.min.js'></script>
    <script src='js/bootstrap-select.js'></script>
    <script src='js/general-js.js'></script>
    <script src="js/select2.js"></script>
    <script>
        $(document).ready(function(e){
                $(".toUp").on("keyup change",function(e){$(this).val(this.value.toUpperCase());});
                $('select').select2({
                    placeholder: "Select a State",
                    allowClear: true
                });
            });
    </script>
</body>
</html>

页面内容根据调用url加载。

我需要知道如何克服这个问题。

谢谢大家

【问题讨论】:

    标签: php dynamic swoole


    【解决方案1】:

    你想说的基本上是 - 如何实现路由?请求对象上有一些方法和属性可用,例如 $request->get$request->header,您可以使用它们来检查用户在浏览器中输入的 url。

    将这些与 if else 结合起来,您可以根据 url 将所需的 html 推送到浏览器。

    如果您需要担心的页面不多,这可以满足您的需求。如果您有一些要求很高的场景,您可以查看easyswoole,它提供了一个易于使用的烘焙框架。已经有适用于CodeigniterLaravel 的适配器,以防您正在使用。

    【讨论】:

    • 嗨@Viney,感谢您的帮助。我会落实你的答案并让你知道
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    相关资源
    最近更新 更多