我想爲使用Heroku的網站製作基本的帳戶註冊頁面。我已經安裝了PostGRESQL,並創建了一個名爲users的表格,其中包含所有正確的列。 (我還沒有使用加密但因爲我只是試圖讓這個工作的第一位。)這是我的頁面PHP:使用Heroku製作註冊頁面 - NotFoundException錯誤
<?php
require('../vendor/autoload.php');
require('../includes/config.php');
$app = new Silex\Application();
$app['debug'] = true;
// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array(
'monolog.logfile' => 'php://stderr',
));
// Register the Twig templating engine
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../views',
));
/*checking database*/
// if form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
/**/
//check that all three fields have been filled out
if (empty($_POST["username"])||empty($_POST["password"])||empty($_POST["confirmation"]))
{
apologize("You need to complete the username, password, and confirmation fields.");
exit;
}
//check that password and confirmation are the same
if ($_POST["password"] != $_POST["confirmation"])
{
apologize("Password and confirmation must match.");
exit;
}
if (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))
{
apologize("Email address not valid. Try again.");
exit ;
}
// Register the Postgres database add-on
$dbopts = parse_url(getenv('DATABASE_URL'));
$app->register(new Herrera\Pdo\PdoServiceProvider(),
array (
'pdo.dsn' => 'pgsql:dbname='.ltrim($dbopts["path"],'/').';host='.$dbopts["host"],
'pdo.port' => $dbopts["port"],
'pdo.username' => $dbopts["user"],
'pdo.password' => $dbopts["pass"]
)
);
$st = $app['pdo']->prepare('INSERT INTO users (username, email, hash) VALUES ('. $_POST["username"] . ', ' . $_POST["email"]. ', '. $_POST["password"]. ')');
$st->execute();
$app->get('/db/', function() use($app) {
$st = $app['pdo']->prepare('SELECT username FROM users');
$st->execute();
$names = array();
while ($row = $st->fetch(PDO::FETCH_ASSOC)) {
$app['monolog']->addDebug('Row ' . $row['name']);
$names[] = $row;
}
return $app['twig']->render('database.twig', array(
'names' => $names
));
});
$app->get('/twig/{name}', function($name) use($app) {
return $app['twig']->render('index.twig', array(
'name' => $name,
));
});
$app->run();
//if the registration worked, log the user in
if ($result !== false)
{
//if registration worked, remember that session ID
$rows = query("SELECT LAST_INSERT_ID() AS id");
$id = $rows[0]["id"];
$_SESSION["id"] = $id;
redirect("../index.php");
}
}
else
{
// else render form
render("register_form.php", ["title" => "Register"]);
}
?>
我收到以下錯誤,當我提交頁面:
對不起,您正在尋找的頁面找不到。 2/2 NotFoundHttpException在RouterListener.php管線145:未發現 「POST /」 路線(從 「http://secret-ridge-6332.herokuapp.com/register.php」)
in RouterListener.php line 145
at RouterListener->onKernelRequest(object(GetResponseEvent), 'kernel.request', object(EventDispatcher))
at call_user_func(array(object(RouterListener), 'onKernelRequest'), object(GetResponseEvent), 'kernel.request', object(EventDispatcher)) in EventDispatcher.php line 164
at EventDispatcher->doDispatch(array(array(object(RouterListener), 'onKernelRequest'), array(object(LocaleListener), 'onKernelRequest'), array(object(LogListener), 'onKernelRequest'), array(object(MiddlewareListener), 'onKernelRequest')), 'kernel.request', object(GetResponseEvent)) in EventDispatcher.php line 53
at EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in HttpKernel.php line 126
at HttpKernel->handleRaw(object(Request), '1') in HttpKernel.php line 66
at HttpKernel->handle(object(Request), '1', true) in Application.php line 538
at Application->handle(object(Request)) in Application.php line 515
at Application->run() in register.php line 72
1/2 ResourceNotFoundException在UrlMatcher.php線96:
in UrlMatcher.php line 96
at UrlMatcher->match('/') in RedirectableUrlMatcher.php line 30
at RedirectableUrlMatcher->match('/') in LazyUrlMatcher.php line 51
at LazyUrlMatcher->match('/') in RouterListener.php line 127
at RouterListener->onKernelRequest(object(GetResponseEvent), 'kernel.request', object(EventDispatcher))
at call_user_func(array(object(RouterListener), 'onKernelRequest'), object(GetResponseEvent), 'kernel.request', object(EventDispatcher)) in EventDispatcher.php line 164
at EventDispatcher->doDispatch(array(array(object(RouterListener), 'onKernelRequest'), array(object(LocaleListener), 'onKernelRequest'), array(object(LogListener), 'onKernelRequest'), array(object(MiddlewareListener), 'onKernelRequest')), 'kernel.request', object(GetResponseEvent)) in EventDispatcher.php line 53
at EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in HttpKernel.php line 126
at HttpKernel->handleRaw(object(Request), '1') in HttpKernel.php line 66
at HttpKernel->handle(object(Request), '1', true) in Application.php line 538
at Application->handle(object(Request)) in Application.php line 515
at Application->run() in register.php line 72
任何想法我可能做錯了什麼?謝謝!
非常感謝您花時間回覆。我今天需要一些時間來完成這個工作,絕對是Silex手冊。 – garson 2014-12-05 16:07:04
心靈接受答案然後,@ garson? – dzuelke 2014-12-06 21:14:04