2

所以我一直在尝试在路由中使用“put”方法,我直接从“routes.php”文件中遵循了这个示例:

Route::put('hello/(:any)', function($name)
{
      return "Welcome, $name.";
});

这会返回 404 错误,我真的希望我的代码如下所示。我希望能够从 url 中获取参数并使用它们进行验证,稍后我计划使用编码方法,但现在我只想让路由正常工作,然后再尝试对它们进行编码。任何帮助将不胜感激!!!

Route::put('admin/activate/(:any?)/(:any?)', function($r, $e) {
     return "Random value: $r <br/> Email: $e";
});

您可以在此处找到该页面:http://diverseevolution.com/admin/activate/randomstring/test@gmail.com

这是我的整体“routes.php”文件:

Route::get('/', function() {
     return View::make('homepage.index');
});

///////////////////////////////////////////////////////////////////////////////////////////
///////////////        Administration Account Creation & Login        /////////////////////
///////////////////////////////////////////////////////////////////////////////////////////

// Create account
Route::get('admin/createform', function() {
     return View::make('admin.createform');
});

// action for actual admin creation
Route::post('admin/create', array('before' => 'csrf', function() {
     $rules = array(
          'fname' => 'required|min:3',
          'lname' => 'required|min:3',
          'email' => 'required|email|unique:users',
          'pword' => 'required'
     );

     $validated = Validator::make(Input::all(), $rules);

     if($validated -> fails()) {
          return Redirect::to('admin/createform')->with_input();
     } else {
          $r = Hash::make(time() .'ReAl19dk4-^4$'. $_POST['pword']);

          $user = new User;

          $user -> fname = $_POST['fname'];
          $user -> lname = $_POST['lname'];
          $user -> email = $_POST['email'];
          $user -> pword = Hash::make($_POST['pword']);
          $user -> status = 'unactivated';
          $user -> random = $r;

          if($user -> save()) {

               //////////////////////// Email /////////////////////////////////
               // We still need to make this functionality

               $msg = '
               <h1>Your admin account has been created!</h1>
               <p>Congratulations on creating your new account, there is one last step before your account can be activated. Below is a link, simply follow the link to activate your account, once you have your account will be active and you will be able to login!</p>
               <p><a href="http://diverseevolution.com/admin/activate/'. $r .'/'. $_POST['email'] .'">http://diverseevolution.com/admin/activate/'. $r .'/'. $_POST['email'] .'</a></p>
               <p>Thanks, Diverse Evolution</p>
               ';

                    // Mail headers
                    $headers  = "Reply-To: Diverse Evolution <info@diverseevolution.com>\r\n"; 
                    $headers .= "Return-Path: Diverse Evolution <info@diverseevolution.com>\r\n"; 
                    $headers .= "From: Diverse Evolution <info@diverseevolution.com>\r\n"; 
                    $headers .= "Organization: Diverse Evolution\r\n";
                    $headers .= 'MIME-Version: 1.0' . "\r\n";
                    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                    $headers .= "X-Priority: 3\r\n";
                    $headers .= "X-Mailer: PHP". phpversion() ."\r\n";
                    define('_headers', $headers);

               if(mail($_POST['email'], 'Diverse Evolution Account Created', $msg, _headers)) {
                    return Redirect::to('admin/thanks');
               } else {

               }
          } else {
               return Redirect::to('admin/createform')->with_input();
          }

     }
}));

// creates the thank you page for the admin account creation
Route::get('admin/thanks', function() {
     return View::make('admin/thanks');
});

// account activation email, this is still not working 011613
Route::put('admin/activate/(:any?)/(:any?)', function($r, $e) {
     return "Random value: $r <br/> Email: $e";
});

// Login form
Route::get('admin/loginform', function() {
     return View::make('admin/loginform');
});

// Login action
Route::post('admin/login', array('before' => 'csrf', function() {
     $rules = array(
          'email' => 'required|email',
          'pword' => 'required'
     );

     $validated = Validator::make(Input::all(), $rules);

     if($validated -> fails()) {
          return Redirect::to('admin/loginform')->with_input();
     } else {
          $credentials = array('username' => $_POST['email'], 'password' => $_POST['pword']);

          if (Auth::attempt($credentials)) {
               return Redirect::to('admin/dash');
          } else {
               return Redirect::to('admin/loginform')->with_input();
          }
     }
}));

Route::get('admin/logout', function() {
     Auth::logout();
     return Redirect::to('admin/loginform');
});

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////        Administration Pages        ////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
Route::group(array('before' => 'auth'), function() {
    Route::get('admin/dash', function() {
        return 'Dashboard';
    });
});















/*
|--------------------------------------------------------------------------
| Application 404 & 500 Error Handlers
|--------------------------------------------------------------------------
|
| To centralize and simplify 404 handling, Laravel uses an awesome event
| system to retrieve the response. Feel free to modify this function to
| your tastes and the needs of your application.
|
| Similarly, we use an event to handle the display of 500 level errors
| within the application. These errors are fired when there is an
| uncaught exception thrown in the application.
|
*/

Event::listen('404', function()
{
    return Response::error('404');
});

Event::listen('500', function()
{
    return Response::error('500');
});

/*
|--------------------------------------------------------------------------
| Route Filters
|--------------------------------------------------------------------------
|
| Filters provide a convenient method for attaching functionality to your
| routes. The built-in before and after filters are called before and
| after every request to your application, and you may even create
| other filters that can be attached to individual routes.
|
| Let's walk through an example...
|
| First, define a filter:
|
|       Route::filter('filter', function()
|       {
|           return 'Filtered!';
|       });
|
| Next, attach the filter to a route:
|
|       Route::get('/', array('before' => 'filter', function()
|       {
|           return 'Hello World!';
|       }));
|
*/

Route::filter('before', function()
{
    // Do stuff before every request to your application...
});

Route::filter('after', function($response)
{
    // Do stuff after every request to your application...
});

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

Route::filter('auth', function()
{
    if (Auth::guest()) return Redirect::to('admin/loginform');
});
4

2 回答 2

1

你没有包括你的表格 - 但我猜你没有在表格中包括“PUT”。

echo Form::open('user/profile', 'PUT');

您可以在此处查看有关表单和 PUT 的更多信息。但一般来说,您需要在表单中专门包含 PUT,否则它将只是 POST(浏览器默认)。

于 2013-01-17T09:37:09.780 回答
0

使用 GET 有效吗?

或者

Route::put('hello/(:all)', function($name)
{
      return "Welcome, $name.";
});

都是因为@

于 2013-01-17T15:47:15.917 回答