2014-09-22 74 views
-2

我有幾個視圖顯示編輯按鈕的細節。當用戶點擊編輯按鈕時,他們進入該項目的編輯視圖。從編輯視圖中,我想鏈接回原始視圖。什麼是人們使用的最佳實踐,所以編輯視圖知道把用戶帶回哪裏?鏈接回源視圖的最佳實踐

我在Laravel框架中使用PHP。

實施例:

上/發票/ 1 /細節用戶,點擊編輯到/接觸/ 9 /編輯,點擊保存或取消後,回到/發票/ 1 /細節

或者

用戶在/任務/ 2 /細節,單擊Edit /聯繫人/ 9 /編輯,點擊保存或取消,回去/任務/ 2 /詳細

或者

用戶上/ report/3/detail,cli點擊保存或取消,返回到/ report/3/detail

+0

我沒有使用RESTful路由。這看起來不是我的答案,但我可能會錯過一些東西。 我正在尋找的是這樣的: 用戶開/發票/ 1 /明細,點擊編輯到/聯繫人/ 9 /編輯,點擊保存或取消,返回到/發票/ 1 /明細 或 用戶在/任務/ 2 /詳細信息,點擊編輯到/聯繫人/ 9 /編輯,點擊保存或取消,回到/任務/ 2 /詳細 – user3720435 2014-09-23 01:49:25

回答

0

如果您願意冒險嘗試,您一定會受益於資源控制器(http://laravel.com/docs/4.2/controllers#restful-resource-controllers)。採用這些之後,您的詳細意見都會看

public function show($id) {...} 

和你的編輯的觀點都會像

public function edit($id) {...} 

和路由會或多或少手柄本身。

假設你已經採用了這種慣例,你可以在基礎控制器中放置一些通用邏輯,並讓你的獨立控制器擴展它們。

一種基站控制器可以有這樣的東西:

<?php 

use Illuminate\Routing\Controller as Controller; 

class BaseController extends Controller 
{ 
    /** 
    * Returns the routable action string for editing this resource 
    * @return string 
    */ 
    final protected function getEditAction() 
    { 
     return __CLASS__ . '@edit'; 
    } 

    /** 
    * Returns the routable action string for showing this resource 
    * @return string 
    */ 
    final protected function getShowAction() 
    { 
     return __CLASS__ . '@show'; 
    } 
} 

然後,延長你的基本控制器控制器,你可以做這樣的東西:

// Redirect to the detail page upon save 
return Redirect::action($this->getShowAction()); 

// Pass a link to the detail page into a view 
return View::make('foo.bar', ['back_url' => URL::action($this->getShowAction())]); 

等。

+0

謝謝。使用GET參數是我如何做的。如果有更好的方法尋找想法。 – user3720435 2014-09-23 19:40:23