【发布时间】:2014-08-23 03:40:51
【问题描述】:
页面:listUsers.php
我有一个按钮
<button data-user-id="5" class="btn btn-info permissions" data-toggle="modal" data-target="#myModal" type="button">Edit</button>
触发下面的引导模式。
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Manage Permissions</h4>
</div>
<div class="modal-body">
<form id="permissions" class="form-horizontal" role="form" method="post">
<div class="form-group">
<div class="col-md-3">
<label for="email">Email:</label>
<input class="form-control" name="email" type="text" id="email">
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<label for="phone">Phone:</label>
<input class="form-control" name="phone" type="text" id="phone">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
我希望使用特定的用户数据填充引导模式表单,以便我可以对其进行编辑。单击编辑时,我使用jQuery get 将控制权传递给获取特定用户的控制器。
$(".permissions").click(function(event){
var userid = $(this).data('user-id'));
$.get("somecontroller/getUser", {userid: userid, status: status}, function(response){
// to do....
// how to populate the form.
});
return false;
});
控制器方法是
public function getUser($id)
{
$user = UserModel::find($id);
if (is_null($user))
{
return Redirect::route('users.index');
}
return View::make('users.listUsers', compact('user'));
// return which view? Do I need to create a new view?
// I want the query result to be available to the modal form in listUsers.php which gets triggered after clicking the edit button in listUsers.php
}
【问题讨论】:
标签: jquery ajax twitter-bootstrap laravel modal-dialog