Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel:在什么情况下,服务调用视图,而不是控制器同时处理调用服务和调用视图? 考虑一下下面的控制器: 类UsersController扩展控制器{ public function index() { // some index stuff } public function ajax() { // This is how I like to do CRUD if(Input::get('action') == "edit"){ return $this->edit(Input::get('id')); } if(Input::post('action') == "update"){ return $this->update(Input::all()); } ... } private function edit($id) { // Let's populate an edit users dialog (popup) $viewData = array(); // Call edit method of my Users service & send that data to view // (Note: "with" is a Laravel Helper) return View::make('users.usersEdit', with(new Users)->edit($id)); // Or should I just have the service take care of the view, like this: // return with(new Users)->edit($id); } }_Php_Design Patterns_Model View Controller_Laravel_Laravel 4 - Fatal编程技术网

Php Laravel:在什么情况下,服务调用视图,而不是控制器同时处理调用服务和调用视图? 考虑一下下面的控制器: 类UsersController扩展控制器{ public function index() { // some index stuff } public function ajax() { // This is how I like to do CRUD if(Input::get('action') == "edit"){ return $this->edit(Input::get('id')); } if(Input::post('action') == "update"){ return $this->update(Input::all()); } ... } private function edit($id) { // Let's populate an edit users dialog (popup) $viewData = array(); // Call edit method of my Users service & send that data to view // (Note: "with" is a Laravel Helper) return View::make('users.usersEdit', with(new Users)->edit($id)); // Or should I just have the service take care of the view, like this: // return with(new Users)->edit($id); } }

Php Laravel:在什么情况下,服务调用视图,而不是控制器同时处理调用服务和调用视图? 考虑一下下面的控制器: 类UsersController扩展控制器{ public function index() { // some index stuff } public function ajax() { // This is how I like to do CRUD if(Input::get('action') == "edit"){ return $this->edit(Input::get('id')); } if(Input::post('action') == "update"){ return $this->update(Input::all()); } ... } private function edit($id) { // Let's populate an edit users dialog (popup) $viewData = array(); // Call edit method of my Users service & send that data to view // (Note: "with" is a Laravel Helper) return View::make('users.usersEdit', with(new Users)->edit($id)); // Or should I just have the service take care of the view, like this: // return with(new Users)->edit($id); } },php,design-patterns,model-view-controller,laravel,laravel-4,Php,Design Patterns,Model View Controller,Laravel,Laravel 4,本着“瘦控制器,胖服务”的精神…(我的口号)… 如果我非常确信我的用户服务(此处未显示)的编辑方法始终需要相应的视图,我是否应该从服务调用视图(而不是从我的用户控制器调用视图,如上所示)?对于编辑用户方法,您的视图不是要求,它是结果的输出用户是域逻辑。理想情况下,它应该对Laravel几乎没有依赖性,因此您可以将其粘贴到另一个框架中,而无需修改 控制器是返回视图的最佳场所。绝对不是在您的域逻辑中。:)Ah…因为我们想说的是,服务可能支持其他视图。我们希望尽可能与域逻辑保持分离。好的,只是需要其他

本着“瘦控制器,胖服务”的精神…(我的口号)…


如果我非常确信我的用户服务(此处未显示)的编辑方法始终需要相应的视图,我是否应该从服务调用视图(而不是从我的用户控制器调用视图,如上所示)?

对于编辑用户方法,您的视图不是要求,它是结果的输出
用户
是域逻辑。理想情况下,它应该对Laravel几乎没有依赖性,因此您可以将其粘贴到另一个框架中,而无需修改


控制器是返回视图的最佳场所。绝对不是在您的域逻辑中。:)

Ah…因为我们想说的是,服务可能支持其他视图。我们希望尽可能与域逻辑保持分离。好的,只是需要其他SO用户的额外信心。也许这个问题会帮助其他用户rs也一样。谢谢。您的域逻辑/服务不应该关心任何视图。它被设计用于执行特定任务,就是这样。您的控制器调用该服务,传递任何相关输入,然后根据结果向用户输出一些内容。但是,是的,听起来您已经得到了它。:)