Home > Backend Development > PHP Tutorial > two steps from hell Minor2 first application Hello World

two steps from hell Minor2 first application Hello World

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 08:33:14
Original
1323 people have browsed it

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>
Copy after login

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

2.1.2 Create a controller

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

<?<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>View<span>::render(<span><span>'Demo:Hello:hello.php<span>', [<span><span>'name<span>' <span>=> <span><span>'World<span>']);</span></span></span><span>    }
}    </span>
Copy after login

2.1.3 Create view file

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

Hello <?= <span>$name</span>?>
Copy after login

Then in the browser Visit: http://xxx.xxx.xxx/helloworld and you can see Hello World

The above introduces the first application of two steps from hell Minor2 Hello World, including the content of two steps from hell. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template