저는 지금이 altorouter를 몇 주 동안 사용해 왔습니다. 이것은 그물이나 공식 사이트에서 많은 예제가없는 좋은 라우터가 될 것으로 보인다. 어떻게 든 그것을 이해하고 일을 끝내야합니다.AltoRouter GET POST 방법은 어떻게 작동합니까?
나는 altorouter를 사용하여 기본 GET 및 POST를 시도했지만 이것이 올바른 방법인지 여부를 알지 못합니다. PHP에서
간단한 GET 방식
<html>
<head>
</head>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
내가
<?php
require 'library/AltoRouter.php';
$router = new AltoRouter();
$router->setBasePath('/AltRouter');
$router->map('GET','/', function() {require __DIR__ . '/catalog/controller/home.php';}, 'home');
$router->map('GET|POST','/aboutus/', function() {require __DIR__ . '/catalog/controller/aboutus.php';}, 'aboutus');
$router->map('GET|POST','/contactus/', function() {require __DIR__ . '/catalog/controller/contactus.php';}, 'contactus');
$router->map('GET|POST','/welcome/', function() {require __DIR__ . '/catalog/controller/welcome.php';}, 'welcome');
$match = $router->match();
if($match && is_callable($match['target'])) {
call_user_func_array($match['target'], $match['params']);
} else {
// no route matched
header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}
contactus.php Index.php는
AltoRouter를 사용했던 방법 (GET 메서드)
,210이 작품 몇 가지 이상한 이유로
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
welcome.php 그러나 나는 이것이 옳지 않다 생각합니다. 이유 : 나는 양식을 제출 한 후 얻을 URL로 page.Where이
http://localhost/altrouter/contactus/
없음 인 GET 방식으로 전송 된 정보는 모두가 볼 수, 변수가 URL에 표시됩니다, 그것은 북마크 할 수 있습니다 변수는 URL에 양식을 제출 한 후에 표시됩니다.
이제 POST 방법에 대해,이 하나가 당신에게 알려줘야합니다. 우리가 어떻게해야하는지 알려주는 것입니다.
Index.php는
same as the one posted above
aboutus.php (POST 방식 사용)
<html>
<head>
</head>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["first_name"];
$email = $_POST["email_address"];
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
}
?>
<form action="<?php $_SERVER["PHP_SELF"]?>" method="post">
Name: <input type="text" name="first_name">
<br><br>
E-mail: <input type="text" name="email_address">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
이 작동
데이터는 URL
를 제출 한 후, 밖으로 echo'ed 게시 됨http://localhost/altrouter/aboutus/
무엇이 옳고 그른지 알려주세요.