2015-01-21 242 views
1

我有兩個控制器和一個控制器調用另一個控制器。我在控制器1上完成了一些處理,並希望將數據傳遞給控制器​​2以進行進一步處理。Laravel路由:如何將參數/參數從一個控制器傳遞到控制器

控制器1:

public function processData() 
    { 
    $paymenttypeid = 「123」; 
    $transid = 「124」; 
    return Redirect::action('[email protected]'); 
    } 

控制器2:

public function getData($paymenttypeid, $transid) 
{ 
} 

錯誤:

Missing argument 1 for Controller2::getData() 

我如何通過變元從控制器1到控制器2?

回答

1

這真的不是一個好辦法。

但是,如果你真的想重定向和傳遞數據,如果他們都像這樣它會更容易:

<?php 

class TestController extends BaseController { 

    public function test1() 
    { 
     $one = 'This is the first variable.'; 
     $two = 'This is the second variable'; 

     return Redirect::action('[email protected]', compact('one', 'two')); 
    } 

    public function test2() 
    { 
     $one = Request::get('one'); 
     $two = Request::get('two'); 

     dd([$one, $two]); 
    } 

} 

,我不需要在控制器方法的參數。

皮膚有很多方法可以使貓變得光滑,而你所要做的並不是一件好事。我建議先看看如何使用服務對象,如this video中所述,以及無數的教程。

If you're not careful, very quickly, your controllers can become unwieldy. Worse, what happens when you want to call a controller method from another controller? Yikes! One solution is to use service objects, to isolate our domain from the HTTP layer.

-Jeffrey Way

+0

謝謝你,我正在看服務對象。 – user3851557 2015-01-21 05:34:32

相關問題