Home >php教程 >php手册 >Minor [PHP Framework] 2. The first application Hello World, minorhello

Minor [PHP Framework] 2. The first application Hello World, minorhello

WBOY
WBOYOriginal
2016-07-06 14:25:281481browse

Minor【PHP Framework】2. The first application Hello World, minorhello

2.1 Hello World

 2.1.1 Configure routing

Add the following configuration in the app/Config/routes.php file:

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

After this configuration, when we access http://xxx.xxx.xxx/helloworld in the browser, the hello method in AppModulesDemoControllerHelloController will be executed

 2.1.2 Create controller

Create a folder under the app/Modules folder: Demo/Controller/, then create the file HelloController.php, and then write in the file:

<?<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 Create view file

Create the folder /Tpl/Hello/ under the app/Modules/Demo/ folder and then create hello.php:

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

Then visit: http://xxx.xxx.xxx/helloworld in the browser to see Hello World

Statement:
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