如何通过响应/请求发送数组?

时间:2017-12-15 08:18:48

标签: symfony symfony-2.7

我有以下问题:

我使用具有以下两个功能的Controller:

这两个功能都有自己的路线 @see routing

public function indexAction(Request $request)
{


    $searchForm = $this->getSearchForm();
    $searchForm->handleRequest($request);
    **$data** = $searchForm->getData();


    if($searchForm->isValid()){
        if(!$data['birthdate'] && !$data['birthyear'] && !$data['patientID'] && !$data['patientNO']){
            $searchForm->addError(new FormError("Please specify at least one search parameter."));
        }
        else
        {    

            return  $this->forward('GeneralCommonBundle:DataHome:result', array(
            'limit'  => '20',
            'offset' => '0'
            ));

          //return $this->redirect($this->generateUrl('result', array('limit' => '20', 'offset' => '0')));
        }
    }

  . . . . . 


}

public function resultAction(Request $request, $limit, $offset){ 


$repo = $this->getDoctrine()->getManager()->getRepository('DataLiveBundle:DataAPatient');
$qb = $repo->getFindingPatientQuery($data['birthdate'], 
$data['patientID'],$data['birthyear'] ,$data['patientNO'], $data['center'], $data['registry'] ,$data['study']);


                    $total = $repo->countQueryResults($qb);

                    $qb = $repo->addLimitToQuery($qb, $limit, $offset);


                    $paginationOptions = array(
                        'total' => $total,
                        'limit' => $limit,
                        'offset' => $offset
                    );  

                    //$query = $qb->getQuery(); 

                    $entities = $repo->getResults($qb);         

            return $this->render('GeneralCommonBundle:DataHome:show.html.twig', array(
            'records'=> $entities,
            'isNew' => false,
            'paginationOptions' => $paginationOptions,
            'newrecord' => false,
            'birthdate'=> $data['birthdate'],
            'patientID'=> $data['patientID'],
            'birthyear'=> $data['birthyear'],
            'patientNO'=> $data['patientNO'],
            'center'   => $data['center'],
            'registry' => $data['registry'],
            'study'    => $data['study']
            ));

}

在函数indexAction中我应该转发到下一个函数(resultAction),因为我需要一个新的URL。我还需要函数resultAction中的函数indexAction中的 $ data 生成,但我不知道,我怎么能用数组作为参数。

路由文件看起来如此:

dataHome:
pattern:  /home
defaults: { _controller: "GeneralCommonBundle:DataHome:index"}

result:
pattern:  /{limit}/{offset}/result
defaults: { _controller: "GeneralCommonBundle:DataHome:result", limit: 20, offset: 0 }

我尝试使用全局变量(我知道它不是一个很好的范例)因为函数在同一个Controller中,但它不起作用。我也尝试将$ data数组放在Response中..但它也不起作用..

如何使用Array作为参数调用路由? 或者将此数组临时存储,我可以在转发后使用它吗?

感谢您的支持!!

1 个答案:

答案 0 :(得分:0)

你肯定可以在路线中作为参数发送,这是我的快速测试:

extension AppDelegate : MessagingDelegate {
// START refresh_token
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
    print("Firebase registration token: \(fcmToken)")
    print("Received Remote Message: 1\nCheck Out:\n")

}
// END refresh_token
// START ios 10 data message
// Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
// To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true.
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
    print("Received data message: \(remoteMessage.appData)")
    print("Received Remote Message: 2\nCheck Out:\n")
}




// Receive data message on iOS 10 devices while app is in the foreground.
func application(received remoteMessage: MessagingRemoteMessage) {
    print("Received Remote Message: 3\nCheck In:\n")
    debugPrint(remoteMessage.appData)
    print("Received Remote Message: 3\nCheck Out:\n")

 }
   // END ios 10 data message
}

但请记住,GET对字符串长度有一些限制,我认为使用会话变量会更合适,只需在indexAction中设置序列化数据然后在resultAction中获取