如何向函数提交多个请求以发送所有提交的请求
How to submit multiple requests to the function to send all submitted requests
我正在尝试将多个请求提交给一个函数,该函数将它们写入一个会话,然后 returns 它们
这里我提交数据给函数
$this->Notification->build('error', 'Test', 'danger', 'bottom-left', 0, 'true');
$this->Notification->build('error', 'Test1', 'danger', 'bottom-left', 0, 'true');
这是我们使用的函数
public function build($title, $description, $type, $position, $closeTimeout, $showProgress)
{
$notify = '<script>';
$notify .= 'Notification.notify({';
$notify .= 'title: "'.esc($title).'",';
$notify .= 'description: "'.esc($description).'",';
$notify .= 'image: {visible: true},';
$notify .= 'type: "'.$type.'",';
$notify .= 'position: "'.$position.'",';
$notify .= 'closeTimeout: "'.$closeTimeout.'",';
$notify .= 'showProgress: "'.$showProgress.'",';
//$notify. .= '';
//$notify. .= '';
//$notify. .= '';
//$notify. .= '';
$notify .= '});</script>';
$notify = $this->Session->setFlashData("notify", $notify); // records a session named "notify"
return true;
}
通话环节
<?php if (session()->get('notify')) : ?>
<?= session()->get('notify'); ?>
<?php endif; ?>
当它执行脚本时 returns 只有最后一个请求 - $this->Notification->build('error', 'Test1', 'danger', 'bottom-left', 0, 'true');
你可以传递一个数组,否则你所做的就是每次都覆盖会话密钥值,所以稍微修改一下方法并将一个数组传递给 setFlashData()
public function build($title, $description, $type, $position,
$closeTimeout, $showProgress)
{
$notify = '<script>';
$notify .= 'Notification.notify({';
$notify .= 'title: "'.esc($title).'",';
$notify .= 'description: "'.esc($description).'",';
$notify .= 'image: {visible: true},';
$notify .= 'type: "'.$type.'",';
$notify .= 'position: "'.$position.'",';
$notify .= 'closeTimeout: "'.$closeTimeout.'",';
$notify .= 'showProgress: "'.$showProgress.'",';
$notify .= '});</script>';
return $notify;
}
// call it
$flash = [];
$flash[] = $this->Notification->build('error', 'Test', 'danger', 'bottom-left', 0, 'true');
$flash[] = $this->Notification->build('error', 'Test1', 'danger', 'bottom-left', 0, 'true');
$this->Session->setFlashData("notify", $flash);
我正在尝试将多个请求提交给一个函数,该函数将它们写入一个会话,然后 returns 它们
这里我提交数据给函数
$this->Notification->build('error', 'Test', 'danger', 'bottom-left', 0, 'true');
$this->Notification->build('error', 'Test1', 'danger', 'bottom-left', 0, 'true');
这是我们使用的函数
public function build($title, $description, $type, $position, $closeTimeout, $showProgress)
{
$notify = '<script>';
$notify .= 'Notification.notify({';
$notify .= 'title: "'.esc($title).'",';
$notify .= 'description: "'.esc($description).'",';
$notify .= 'image: {visible: true},';
$notify .= 'type: "'.$type.'",';
$notify .= 'position: "'.$position.'",';
$notify .= 'closeTimeout: "'.$closeTimeout.'",';
$notify .= 'showProgress: "'.$showProgress.'",';
//$notify. .= '';
//$notify. .= '';
//$notify. .= '';
//$notify. .= '';
$notify .= '});</script>';
$notify = $this->Session->setFlashData("notify", $notify); // records a session named "notify"
return true;
}
通话环节
<?php if (session()->get('notify')) : ?>
<?= session()->get('notify'); ?>
<?php endif; ?>
当它执行脚本时 returns 只有最后一个请求 - $this->Notification->build('error', 'Test1', 'danger', 'bottom-left', 0, 'true');
你可以传递一个数组,否则你所做的就是每次都覆盖会话密钥值,所以稍微修改一下方法并将一个数组传递给 setFlashData()
public function build($title, $description, $type, $position,
$closeTimeout, $showProgress)
{
$notify = '<script>';
$notify .= 'Notification.notify({';
$notify .= 'title: "'.esc($title).'",';
$notify .= 'description: "'.esc($description).'",';
$notify .= 'image: {visible: true},';
$notify .= 'type: "'.$type.'",';
$notify .= 'position: "'.$position.'",';
$notify .= 'closeTimeout: "'.$closeTimeout.'",';
$notify .= 'showProgress: "'.$showProgress.'",';
$notify .= '});</script>';
return $notify;
}
// call it
$flash = [];
$flash[] = $this->Notification->build('error', 'Test', 'danger', 'bottom-left', 0, 'true');
$flash[] = $this->Notification->build('error', 'Test1', 'danger', 'bottom-left', 0, 'true');
$this->Session->setFlashData("notify", $flash);