1、环境要求
2、框架安装
# 创建项目composer create-project easyswoole/app easyswoole# 进入项目目录并启动cd easyswoolephp easyswoole start
推荐(免费):swoole
3、认识easyswoole框架的目录结构
https://www.easyswoole.com/manual/2.x/cn/_book/introduction/structure.html
4、新建控制器
app\httpcontroller 是控制器目录,我们新建一个user.php,代码如下:
<?phpnamespace app\httpcontroller;use easyswoole\core\http\abstractinterface\controller;class user extends controller{ public function index() { $data['id'] = 101; $data['name'] = "jack"; $this->response()->withheader('content-type','application/json;charset=utf-8'); $this->response()->write(json_encode($data)); } public function test() { $this->response()->write("test method for the user controller"); }}
重新启动项目,浏览器访问
访问http://10.211.55.17:9501/user/ 就是访问的http://10.211.55.17:9501/user/index。说明控制器中index() 是默认方法。
以上就是swoole框架之easyswoole安装的详细内容。
