php mi add:route "routeName"
php mi add:route Home
"Home"
in the windows/Routes
directory.
The file created will resemble the format below:
<?php namespace spoova\mi\windows\Routes\Home; use Window; class Home extends Window { public function __construct(){ self::call($this, [ window(":") => 'home' ] ); } public function home() { // self::load('home', fn() => compile() ); } /** * Add name of routes * * @return array */ public static function addRoutes(array $array = []) : array { return [ // 'routeName' => 'routePath' ]; } }
app
, once the file above is generated, when you visit the url address
http://localhost/app/home
on your browser, you should see a blank page. The home()
method above is
called from the __construct()
method using the shutter call()
method. This will be discussed later in the course of this tutorial.
However, since we know that the home()
method is called, we can load our rex
template files from the particular method called. To do this,
let's create a new template file called "home"
by running the command below:
php mi add:rex home
home.rex.php
file into the windows/Rex
directory. Once this file is
added, we will add our first "hello world"
text into the template file and load it from the root
method. The final template and route file Home.php
will look like the format below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Home</title> </head> <body> Hello World </body> </html>
<?php namespace spoova\mi\windows\Routes\Home; use Window; class Home extends Window { public function __construct(){ self::call($this, [ window(":") => 'home' ] ); } function home() { self::load('home', fn() => compile() ); //template loaded } /** * Add name of routes * * @return array */ public static function addRoutes(array $array = []) : array { return [ // 'routeName' => 'routePath' ]; } }
http://localhost/app/home
on the browser, the text "Hello World"
will be
displayed.