Example App
Add a BMI calculator page using Javascript¶
-
Open the main config file located at
app/config/default/application.json -
Find the menu section, for example:
"menu": {
"main": [{
"href": "/examples/examples",
"title": "Examples"
}, {
"href": "/examples/markup",
"title": "Mark-Up"
} ...
Insert the following json code under main:
{
"href":"/examples/bmi",
"title":"BMI"
}
-
Open the routing config file located at
/app/config/default/routes.json. We can see that sites located at/will be routed to the controller Index and sites located at/examples/will be routed to the controller Example. -
Open the controller Example located at
/app/controllers/Examples.php -
Add the following function inside the Examples class
-
Create a file called
bmi.phpunder/app/views/examples/ -
Open the bmi.php and add the following code:
-
Create
example.jsunder the folder/app/themes/hello/js/ -
Paste the following code to
example.js
-
Save all changes, and open a web brower.
-
Go to localhost, click the BMI tab on the menu, and then you should see this.
Add a BMI calculator page using new route¶
-
Open the main config file located at
/app/config/default/application.json -
Find the menu section and insert the following code.
{
"href":"/Calculator/bmi_version2",
"title":"BMI"
}
-
Open the routing config file located at
app/config/default/routes.json. Add a new rule to the route.["Calculator/([a-zA-Z0-9_\-/]+)", "\app\controllers\Calculator"], -
Then, we will need to create a new controller for the new route. To create a new controller, create
Calculator.phpunder the folder/app/controllers/ -
Paste the following code inside
Calculator.php
-
Create a view called
bmi.phpunder/app/views/examples/ -
Open bmi.php and add the following code:
-
Create a file called
bmi_post.phpunder/app/views/examples/ -
Open the bmi_post.php and add the following code:
-
Save all changes, and open the site in your web brower.
-
Click the BMI tab on the menu, and then you should see the following results.

