0

我以前从未使用过会话,我正在尝试找出处理此问题的最佳方法。我基本上正在尝试做:

选择服务的第一步

2步选择时间

3 步审查和书籍

我可以使用 mysql 让它毫无问题地工作。我通常会做的是在每一步之后将信息保存到数据库中,当我进入审查部分时,我会保存所有信息并且没问题。

但是,我认为这不是解决此问题的最佳方法,并且可能会导致以后出现问题(如果他们停在第 2 步等等怎么办)

我决定尝试 Laravel 4 会话,保存会话并继续下一步非常容易。但是,当我到达最后一步时,我需要加入 mysql 表以完全显示有关他们的预订信息。我可以使用会话信息来加入信息吗?我可以使用会话数据库来保存这些信息吗?或者使用不同的表?

我的控制器在查看信息后发布:

public function getReview() { 

//sets id of user
$user = User::find(Auth::user()->id);  

//gets the time and date that they booked from @getSchedule     
$scheduler = Session::get('schedule');

//formats time to put in db
$date = strtotime($scheduler['date']);

//same thing as the line above
$dateFormat = date('Y-m-d',$date);      

//model to save the schedule
$schedule = new Schedule();

$schedule->userID = $user->id;
$schedule->date = $dateFormat;
$schedule->block = $scheduler['timeslot'];
$schedule->status = "1";

$schedule->save();

//gets the services the user picked from @getServices
$service = Session::get('service');

//saves the services as individual rows in db table
foreach($service as $services)
{           
    if(!empty($services)) {
        $service = new Service();

        $service->userID = $user->id;
        $service->services = $services;

        $service->save();
    }
}



        return Redirect::to('dashboard');
}   

这是 GET 评论页面(我遇到了所有 JOINS 的问题)

    public function showReview() { 
$user = User::find(Auth::user()->id);           
//show the information and confirm that they want all this crap...if they do..save it and return them to their dashboard    

$time = DB::table('bk_schedule')
        ->leftJoin('bk_timeslot', 'bk_schedule.block', '=', 'bk_timeslot.id')
        ->where('bk_schedule.id', Auth::user()->id)->first();       

$date = strtotime($time->date);

$dateFormat = date('D: F d, Y',$date);  

$service = Session::get('service');     

$serviceSummary = DB::table('bk_service')
        ->leftJoin('pr_service', 'pr_service.id', '=', 'bk_service.services')
        ->where('bk_service.userID', Auth::user()->id)
        ->get();

$total = DB::table('bk_service')
        ->leftJoin('pr_service', 'pr_service.id', '=', 'bk_service.services')
        ->where('bk_service.userID', Auth::user()->id)
        ->sum('pr_service.price');      

return View::make('book.review', array('pageTitle' => 'Booking Appointment Review and Finalize', 'service' => $service, 'date' => $dateFormat, 
    'time' => $time, 'email' => $user->email, 'serviceSummary' => $serviceSummary, 'total' => $total)); 
}   

如果他们不提交到POST,是否可以将信息保存在GET并删除它?我可以使用我的会话数据并使用我拥有的 MySQL 查询吗?

4

1 回答 1

0

您不了解会话是什么,随着您的接近,用户将无法同时填写多个表单(在多个选项卡中打开)。

因此,执行此操作的一般方法是:

  1. 第一页仅显示带有一些字段的 HTML 代码
  2. 用户选择它们并将数据 POST 回服务器
  3. 服务器验证数据并打开另一个带有新字段的 HTML 页面,并添加几个“隐藏”字段,其中包含在步骤 1 中选择的值(当然服务器可以向 page1 显示错误消息)
  4. 用户发布此表单,服务器可以打开第三个表单,其中新的可见字段和所有以前的字段都存储在隐藏输入中
  5. 最后,用户将表单发布到最后一页,您可以在其中拥有所有先前页面的所有数据。

请注意:另一种方法是在会话中存储“临时”数据,为此您需要在第二步获取一些生成的 ID 并将其通过页面传递,如前所述

于 2013-10-10T00:40:56.670 回答