Home php教程 php手册 Minor【 PHP框架】2.第一个应用 Hello World

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

Jun 16, 2016 am 08:39 AM

2.1 Hello World

  2.1.1 配置路由

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

<span style="color: #0000ff;">return</span><span style="color: #000000;"> [
   </span>...
    '/helloworld'            =><span style="color: #000000;">  [
        </span>'name'                =>    'helloworld',
        'controller'        =>    'App\Modules\Demo\Controller\HelloController',
        'action'            =>    'hello'<span style="color: #000000;">
    ]</span>,<span style="color: #000000;">
];</span>
Copy after login

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

  2.1.2 创建控制器

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

<span style="color: #000000;">php
namespace App\Modules\Demo\Controller;
</span><span style="color: #0000ff;">use</span><span style="color: #000000;"> Minor\Controller\Controller;
</span><span style="color: #0000ff;">class</span> HelloController <span style="color: #0000ff;">extends</span><span style="color: #000000;"> Controller
{
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> hello()
    {</span><span style="color: #0000ff;">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 style="color: #000000;">
    }
}    </span>
Copy after login

  2.1.3 创建视图文件

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

Hello = <span style="color: #800080;">$name</span>?>
Copy after login

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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1249
24