Zend Framework V2에서 리디렉션에서 URL 매개 변수를 설정하십시오
-
11-12-2019 - |
문제
내 컨트롤러에서 리디렉션 스크립트 (Zend Framework 2)
return $this->redirect()->toRoute('default', array(
'controller' => 'admin',
'action' => 'index'
));
.
현재 localhost/zf2/public/admin/index
로 리디렉션
여분의 매개 변수로 어떻게 리디렉션 할 수 있습니까?
처럼 :
localhost/zf2/public/admin/index/update/1
또는 localhost/zf2/public/admin/index/page/2
나는 이것을 시도했다 :
return $this->redirect()->toRoute('default', array(
'controller' => 'admin',
'action' => 'index'
'param' => 'updated/1'
));
.
그러나 localhost/ttacounting/public/admin/index/updated%2F1
로 리디렉션됩니다.
해결책
이 하나는 작업 예입니다. 경로 스크립트
$this->redirect()->toRoute('myaccount', array(
'controller' => 'admin',
'action' => 'index',
'param1' =>'updated',
'param2'=>'1'
));
.
그런 다음 module.config.php에서 매개 변수를 설정합니다
'myaccount' => array(
'type' => 'Segment',
'options' => array(
'route' => '/myaccount[/:action][/:param1][/:param2]',
'defaults' => array(
'controller' => 'Main\Controller\MyAccount',
'action' => 'index',
),
),
),
.
이렇게하면 myAccountController, param1= 'updated'및 param2= '1'인 indexAction을 사용하면됩니다. 그러나 예제 사례에서는 매개 변수 이름 '업데이트'및 매개 변수 값 '1'로 업데이트해야합니다.
다른 팁
이것은 나를 위해 작동합니다.
경로 :
'user_view' => array(
'type' => 'Segment',
'options' => array(
'route' => '/user/view[/:user_id]',
'defaults' => array(
'controller' => 'user',
'action' => 'viewUser',
),
),
), // End of user_view route
.
및 컨트롤러의 리디렉션 :
return $this->redirect()->toRoute('user_view', array('user_id'=>$user_id));
.
리디렉션 문의 배열 키는 경로 세그먼트에 해당합니다. [/ : user_id]= 'user_id'=> $ user_id
이 명령문은 Localhost / Lead / Edit / 112345 : 로 리디렉션합니다.
return $this->redirect()->toRoute('leads', array(
'action' => 'edit',
'id' => 112345
));
.
ID는 내가 기대하는 매개 변수입니다.
그것은 도움이되기를 바랍니다.
다른 방법은 경로를 업데이트하는 대신 3 개의 매개 변수 (ZF3에서 테스트 됨)로 전달하는 것입니다.
$this->redirect()->toRoute('dashboard', [], ['query' => ['welcome' => 1]]);
. 위의 해결책에서 일부를 시도했지만 그 중 누구도 나를 위해 일하고있었습니다.나는 다음과 함께왔다.
//Return to specific product pricing
return $this->redirect()->toRoute('showpricing', array('id' => $form_values['id']));
/* show pricing */
'showpricing' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/product/showpricing[?id=:id]',
'defaults' => array(
'controller' => 'Product\Controller\Product',
'action' => 'showpricing',
)
)
),
.
이것은 누군가를 도울 것입니다.
이전 하나의 대신이 경로를 사용해보십시오.
return $this->redirect()->toRoute('default', [
'controller' => 'admin',
'action' => 'index'
'updated' => '1'
]);
.