ZiBaT
=> Peter Levinsky
=> Programming => exercise |
PHP Twig |
Updated : 2016-09-26
|
revised after Anders Børjesson
To create a PHP application in PHPStorm using a MVC framework (here Twig).
In this exercise you will make a simple calculator using PHP.
Make a PHP web page (e.g. 'index.php') with a PHP/HTML form element.
This page / form should include two textfield for the two numbers to add plus a button to send the request.
The methods must be post
, not get.
You are to make two pages (split in 'view' and 'control'), to follow the framework twig.
Now make another PHP web page (e.g. 'calculate.php'):
This page is where you do the calculation. Send this result to the view page.
Make a page to present the result (e.g. 'Calculation.html.twig').
Normally you use <form method="post" ...>.
Try to use method="get"
.
What difference does it make?
Use $_REQUEST or $_GET. What is the difference?
General question: How are data transported with HTTP GET and HTTP POST?
The first version of the calculator only does Add ('+').
Next step is to add all 4 operations add, subtract, multiply, divide.
Add a drop down list to the form (HTML select
) with +, -, *, and /, and maybe even more operators.
Adapt the server side to handle different kinds of calculations:
if ... else ... elseif
statements.switch
statement.Make a user defined function to do the calculation.
Make a PHP class calculator.
Inspiration (the first part only. The later part i quite advanced ...)
Put the class calculator in a separate file.
Include the calculator file in the main file using the PHP syntax include or require.
Style your calculator to make it look nicer ...
Style your calculator using the Bootstrap framework.