示例#1
0
文件: app.php 项目: jmalo34/triangle
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Triangle.php";
$app = new Silex\Application();
$app->get("/", function () {
    return "\n        <!DOCTYPE html>\n        <html>\n        <head>\n            <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css'>\n            <title>Type my Triangle</title>\n        </head>\n        <body>\n            <div class='container'>\n                <h1>Is what I have here a triangle?</h1>\n                <p>Complete all fields in the form below to determine if you have the measurements for a triangle.</p>\n                <form action='tri_type'>\n                    <div class='form-group'>\n                        <label for='first_side'>Side 1 (height):</label>\n                        <input id='first_side' name='first_side' class='form-control' type='number'>\n                    </div>\n                    <div class='form-group'>\n                        <label for='second_side'>Side 2 (length):</label>\n                        <input id='second_side' name='second_side' class='form-control' type='number'>\n                    </div>\n                    <div class='form-group'>\n                        <label for='third_side'>Side 3 (width):</label>\n                        <input id='third_side' name='third_side' class='form-control' type='number'>\n                    </div>\n                    <button type='submit' class='btn-success'>Triangle, here?</button>\n                </form>\n            </div>\n        </body>\n        </html>\n        ";
});
//format tri_type page with bootstrap. idk rn how to use it and get the html and needed functions to display and what not. aye!
$app->get("/tri_type", function () {
    $my_triangle = new Triangle($_GET['first_side'], $_GET['second_side'], $_GET['third_side']);
    $area = $my_triangle->area();
    // <head>
    //     <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css'>
    //     <title>Type my Triangle</title>
    // </head>
    // <body>
    // <div class='container'>
    if ($area <= 0) {
        return '<h3>Error: All fields must be set to integers greater than zero.</h3>';
    } else {
        return $my_triangle->type();
    }
    //     </div>
    // </body>
    // </html>
    // ";
});
return $app;