简体   繁体   English

不知道如何用 Swoole 动态加载页面

[英]Dont know how to load page dynamically with Swoole

Hello developper friends.开发者朋友你好。

I'm trying to make old website working with swolle http server but i'm stacking.我正在尝试使旧网站与 swolle http 服务器一起工作,但我正在堆积。 I follow starting tutorial but can't find way to go head.我遵循入门教程,但找不到前进的方向。

<?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();

Now i want to dynamically load my content (like what i use to do with apache server) according to the url but can't find how to do this.现在我想根据 url 动态加载我的内容(就像我用 apache 服务器做的那样),但找不到如何执行此操作。 This is my old index file这是我的旧索引文件

<!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>

The content of the page is loaded according the call url.页面内容根据调用url加载。

Please i need to know how to overcome this.请我需要知道如何克服这一点。

Thanks to all谢谢大家

What you want to say basically is - how implement routing?.你想说的基本上是——如何实现路由? There are a few methods and properties available on request object like $request->get and $request->header that you might use to inspect what url user has entered in browser.请求对象有一些可用的方法和属性,例如$request->get$request->header ,您可以使用它们来检查用户在浏览器中输入的 url。

Combine these with if else and you can push your desired html to browser based on the url.将这些与 if else 结合起来,您可以根据 url 将所需的 html 推送到浏览器。

This is fine for your need if there aren't many pages that you need to worry about.如果您需要担心的页面不多,这可以满足您的需求。 If you have some demanding scenario you may have a look at easyswoole which provides an easy to use baked framework.如果你有一些苛刻的场景,你可以看看easyswoole ,它提供了一个易于使用的烘焙框架。 There are already adapters available for Codeigniter or Laravel incase that is what you are using.目前已经有用于适配器Laravel柜面这是你使用的是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM