2.1 hello world
2.1.1 配置路由
在app/config/routes.php文件中添加如下配置:
return [ ... '/helloworld' => [ 'name' => 'helloworld', 'controller' => 'app\modules\demo\controller\hellocontroller', 'action' => 'hello' ],];
这样配置之后当我们在浏览器中访问http://xxx.xxx.xxx/helloworld时就会执行app\modules\demo\controller\hellocontroller里的hello方法
2.1.2 创建控制器
在app/modules文件夹下创建文件夹: demo/controller/,然后创建文件hellocontroller.php,然后在文件中写:
phpnamespace app\modules\demo\controller;use minor\controller\controller;class hellocontroller extends controller{ publicfunction hello() {returnview::render('demo:hello:hello.php', ['name' => 'world']); }}
2.1.3 创建视图文件
在app/modules/demo/文件夹下创建文件夹/tpl/hello/然后创建hello.php:
hello = $name?>
然后在浏览器中访问:http://xxx.xxx.xxx/helloworld就可以看到hello world了
以上就介绍了two steps from hell minor2第一个应用 hello world,包括了two steps from hell方面的内容,希望对php教程有兴趣的朋友有所帮助。