使用Laravel的注册表

时间:2014-02-26 16:58:57

标签: php laravel

我试图在Laravel上创建一个基本的注册表单,遵循Dayle Rees的教程,特别是 - > This one

当我加载我的注册表时,一切都很好。但是,当我提交时,它说

The requested URL /testserver/registration was not found on this server.

我是一名初学者,希望更好地学习Laravel,所以感谢任何帮助!

这是我的register.blade.php

<!doctype html>
<html lang="en">

<head>
</head>

<body>
<h1>Registration Form</h1>

{{ Form::open(array('url' => '/registration')) }}

    <ul class="errors">
    @foreach($errors->all() as $message)
        <li>{{ $message }}</li>
    @endforeach
    </ul>


    {{-- Username field. ------------------------}}
    {{ Form::label('username', 'Username') }}
    {{ Form::text('username') }}

    {{-- Email address field. -------------------}}
    {{ Form::label('email', 'Email address') }}
    {{ Form::email('email') }}

    {{-- Password field. ------------------------}}
    {{ Form::label('password', 'Password') }}
    {{ Form::password('password') }}

    {{-- Password confirmation field. -----------}}
    {{ Form::label('password_confirmation', 'Password confirmation') }}
    {{ Form::password('password_confirmation') }}

    {{-- Form submit button. --------------------}}
    {{ Form::submit('Register') }}

{{ Form::close() }}
</body>

</html>

这是我的routes.php

Route::get('/', function()
{
    return View::make('register');
});

Route::post('/registration', function()
{
    $data=Input::all();

    // Build the validation constraint set.
    $rules = array(
        'username'   => 'required|min:5|max:15',
        'email'      => 'required|email',
        'password'   => 'required|alpha_num|confirm|min:8'
    );

    // Create a new validator instance.
    $validator = Validator::make($data, $rules);

    if ($validator->passes()) {
        // Normally we would do something with the data.
        return 'Data was saved.';
    }

    return Redirect::to('/')->withErrors($validator);

});

Route::filter('csrf', function()
{
    if (Request::forged()) return Response::error('500');
});

来自页面来源的表单操作 - http://localhost/testserver是我的根文件夹

<form method="POST" action="http://localhost/testserver/registration" accept-charset="UTF-8"><input name="_token" type="hidden" value="LUE1UWguOcyKSbgRyGchfKppRHab504v9p8uEZhQ">

1 个答案:

答案 0 :(得分:3)

您需要在路线中使用POST方法:

Route::post('/registration', function() ...

否则,当您发布表单时,Laravel将找不到该路由。

如果仍未找到您的路线,则.htaccess可能无法正确重写您的网址,可以测试您可以将表单更改为:

{{ Form::open(array('url' => '/index.php/registration')) }}

如果有效,则必须修复VirtualHost或.htaccess。