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

WBOY
Release: 2016-07-12 08:50:26
Original
944 people have browsed it

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

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

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

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133570.htmlTechArticleMinor【PHP Framework】2. The first application is Hello World, minorhello 2.1 Hello World 2.1.1 Configure routing in Add the following configuration to the app/Config/routes.php file: return [ ... '/helloworld'...
Related labels:
source:php.cn
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