Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php symfony当函数服务中的变量为true时,如何创建弹出(细枝)消息?_Php_Symfony_Popup_Twig_Message - Fatal编程技术网

php symfony当函数服务中的变量为true时,如何创建弹出(细枝)消息?

php symfony当函数服务中的变量为true时,如何创建弹出(细枝)消息?,php,symfony,popup,twig,message,Php,Symfony,Popup,Twig,Message,我有一个功能,可以导入一个excel文件,他是在一个服务类。当查询$result为true或false($result为布尔值)时,我不想向表单模板发送弹出式消息 我知道“addFlash”,但控制器中没有,但$result是由控制器调用的服务函数 服务代码如下: $result = mysqli_query($conn, $query); if ($result == true) { /* Here i want to put the confirmation message*/ }

我有一个功能,可以导入一个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

我不明白这一点,但请尝试从服务返回您的消息,例如:

if ($result == true){
   $message = 'Your message here';
   }else{
    $message = 'Your fail message here';
}

return $message;
然后从控制器

如果您想要flash消息:

$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;
       ]);

这回答了你的问题吗@dani45如果这对您有帮助,您能验证或投票支持此响应吗?;)