2015-01-21 5 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() 

어떻게 argumen을 통과 할 제어기 1에서 제어기 2 로의 ts?

답변

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

관련 문제