首页 >php教程 >php手册 >Minor【 PHP框架】2.第一个应用 Hello World,minorhello

Minor【 PHP框架】2.第一个应用 Hello World,minorhello

WBOY
WBOY原创
2016-07-06 14:25:281472浏览

Minor【 PHP框架】2.第一个应用 Hello World,minorhello

2.1 Hello World

  2.1.1 配置路由

  在app/Config/routes.php文件中添加如下配置:

<span>return</span><span> [
   </span>...
    '/helloworld'            =><span>  [
        </span>'name'                =>    'helloworld',
        'controller'        =>    'App\Modules\Demo\Controller\HelloController',
        'action'            =>    'hello'<span>
    ]</span>,<span>
];</span>

  这样配置之后当我们在浏览器中访问http://xxx.xxx.xxx/helloworld时就会执行App\Modules\Demo\Controller\HelloController里的hello方法

  2.1.2 创建控制器

  在app/Modules文件夹下创建文件夹: Demo/Controller/,然后创建文件HelloController.php,然后在文件中写:

<?<span>php
namespace App\Modules\Demo\Controller;
</span><span>use</span><span> Minor\Controller\Controller;
</span><span>class</span> HelloController <span>extends</span><span> Controller
{
    </span><span>public</span> <span>function</span><span> hello()
    {</span><span>return</span> <span class="pl-c1">View<span class="pl-k">::render(<span class="pl-s"><span class="pl-pds">'Demo:Hello:hello.php<span class="pl-pds">', [<span class="pl-s"><span class="pl-pds">'name<span class="pl-pds">' <span class="pl-k">=> <span class="pl-s"><span class="pl-pds">'World<span class="pl-pds">']);</span></span></span></span></span></span></span></span></span></span></span></span><span>
    }
}    </span>

  2.1.3 创建视图文件

  在app/Modules/Demo/文件夹下创建文件夹/Tpl/Hello/然后创建hello.php:

Hello <?= <span>$name</span>?>

  然后在浏览器中访问:http://xxx.xxx.xxx/helloworld就可以看到Hello World了

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn