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