0
我有一個視圖模型和控制器的方法:Laravel - 我知道我的ViewModel,所以我可以將ViewModel傳遞給控制器參數嗎?
class TimesheetViewModel
{
public /* TimesheetTotals */ $TimesheetTotals;
public /* TimesheetEntry[] */ $Timesheets = array();
public /* int */ $AmountOfTimesheetEntries = 1;
}
...
public /* void */ function GetCreate()
{
...
$timesheetViewModel = new TimesheetViewModel();
...
$timesheetViewModel->TimesheetTotals = $timesheetLogic->ColumnSum($timesheetEntries);
$timesheetViewModel->AmountOfTimesheetEntries = count($timesheetEntries);
$timesheetViewModel->Timesheets = $timesheetEntries;
return View::make('Timesheet/Create', array("Model" => $timesheetViewModel));
}
...
我有我的觀點的形式,在我的視圖模型的屬性的完美複製... 是否有辦法有這樣的事情在我的控制器:
...
public /* void */ function PostCreate(TimesheetViewModel $timesheetViewModel)
{
// This will help because I do not have to do Input::all
// and then map it (Or not map it at all and stick with
// an array that could change when someone is working on
// the form fields mucking things up) ?
}
...
它會的!謝謝! – Jimmyt1988