0
這是我用來呈現我的添加項目窗體的方法。我解決了生成消息Serialization of 'Closure' is not allowed
,但我真的不知道是什麼原因造成的。更改$this->userInstance->all()
的位置解決了它。刪除withInput($data)
也使它的工作,但後來我不能發送數據與我的重定向。在Laravel 4中不允許「封閉」的序列化
問題
所以錯誤已經被解決了,但我想知道究竟是爲什麼呢下面的作品該如何解決?
正確版本:
/*
* Add project.
*
**********************************************************************************************************/
public function addProject() {
/*
* When the user is not authorized for the page show unauthorized page.
*/
if(Atomend\Aeuser\AEUser::authorize('add-project') == false) {
return View::make("unauthorized");
}
/*
* Initialize the data array that gets send to the view.
*/
$data = [
"errors" => null
];
/*
* When the form is posted.
*/
if(Input::server("REQUEST_METHOD") == "POST") {
/*
* If the input is valid set the credentials.
*/
if($this->projectInstance->create()) {
/*
* Set the status message and set the status to true.
*/
$data["successes"] = $this->projectInstance->successes();
/*
* Redirect to the user overview on success.
*/
return Redirect::to("/projects")
->withInput($data);
} else {
/*
* Flash the input for usage in the view.
*/
Input::flash();
/*
* Set the data errors variable.
*/
$data["errors"] = $this->projectInstance->errors();
}
}
/*
* Get all users.
*/
$data["users"] = $this->userInstance->readAll();
return View::make("project-add", $data);
}
錯誤版本:
/*
* Add project.
*
**********************************************************************************************************/
public function addProject() {
/*
* When the user is not authorized for the page show unauthorized page.
*/
if(Atomend\Aeuser\AEUser::authorize('add-project') == false) {
return View::make("unauthorized");
}
/*
* Initialize the data array that gets send to the view.
*/
$data = [
"errors" => null
];
/*
* Get all users.
*/
$data["users"] = $this->userInstance->readAll();
/*
* When the form is posted.
*/
if(Input::server("REQUEST_METHOD") == "POST") {
/*
* If the input is valid set the credentials.
*/
if($this->projectInstance->create()) {
/*
* Set the status message and set the status to true.
*/
$data["successes"] = $this->projectInstance->successes();
/*
* Redirect to the user overview on success.
*/
return Redirect::to("/projects")
->withInput($data);
} else {
/*
* Flash the input for usage in the view.
*/
Input::flash();
/*
* Set the data errors variable.
*/
$data["errors"] = $this->projectInstance->errors();
}
}
return View::make("project-add", $data);
}
是的,你說得對,那簡直是愚蠢的。用戶只需使用make,但我也將它們添加到重定向中。謝謝! – sidneydobber