我有一个可以导入excel文件的函数,他在服务类中。当查询$ result为true或false($ result为布尔值)时,我将不会在窗体模板中发送类似弹出消息的消息。
我知道“ addFlash”,但是在控制器中没有,但是$ result在控制器调用的服务函数中。
服务中有代码:
$result = mysqli_query($conn, $query);
if ($result == true) {
/* Here i want to put the confirmation message*/
} else {
/* Here i want to put the fail message*/
}
这里是控制器中的代码:
$targetPath = '../var/uploads/'.$inputFileName;
$importer->import($targetPath); /*function called of the service*/
return $this->render('upload/form.html.twig', [
'importResult' => 'ImportController',
]);
我知道“ addFlash”,但没有在控制器中,但是$ result在由控制器调用的服务函数中
我不明白,但是尝试从service退回您的消息,例如:
if ($result == true){
$message = 'Your message here';
}else{
$message = 'Your fail message here';
}
return $message;
然后从控制器...
如果您想发送即时消息:
$message = $importer->import($targetPath);
$this->addFlash('message',$message);
return $this->render('upload/form.html.twig', [
'importResult' => 'ImportController',
]);
或者如果您想手动操作响应,请尝试:
$message = $importer->import($targetPath);
return $this->render('upload/form.html.twig', [
'importResult' => 'ImportController',
'message' => $message;
]);