我試圖向一個函式提交幾個請求,該函式將這些請求寫入一個會話,然后回傳這些請求
我在這里向函式提交資料
。我在這里提交資料給函式
$this-> Notification-> build('error'/span>, 'Test'/span>, 'danger'/span>, 'bottom-left', 0, 'true')。)
$this-> Notification-> build('error'/span>, 'Test1'/span>, 'danger'/span>, 'bottom-left', 0, 'true')。)
這就是我們使用的函式
public function build($title, $description, $type, $position, $closeTimeout, $showProgress)
{
$notify = '<script> ';
$notify .= 'Notification.notify({'/span>;
$notify .= 'title: "'.esc($title).'", ';
$notify .= 'description: "'.esc($description).'", ';
$notify .= 'image: {visible: true},';
$notify .= 'type: "'.$type.' ",';
$notify .= 'position: "'.$position.' ",';
$notify .= 'closeTimeout: "'.$closeTimeout.' ",';
$notify .= 'showProgress: "'/span>.$showProgress.'",';
//$notify. .='';
//$notify. .='';
//$notify. .='';
//$notify. .='';
$notify .= '});</script> '。
$notify = $this-> Session-> setFlashData("notify", $notify); //記錄一個名為 "notify"的會話。
return true。
}
呼叫會話
<?php if (session()->get('notice') ) : ?>
<?= session()->get('notify'); ? >
<?php endif; ?>
當它執行腳本時,只回傳最后一個請求 - $this->Notification->build('error', 'Test1', 'danger', 'bottom-left', 0, 'true') ;
uj5u.com熱心網友回復:
你可以傳遞一個陣列,但否則你所做的就是每次都覆寫會話鍵的值,所以修改一下方法,給setFlashData()傳遞一個陣列
public function build($title, $description, $type, $position,
$closeTimeout, $showProgress)
{
$notify = '<script> ';
$notify .= 'Notification.notify({'/span>;
$notify .= 'title: "'.esc($title).'", ';
$notify .= 'description: "'.esc($description).'", ';
$notify .= 'image: {visible: true},';
$notify .= 'type: "'.$type.' ",';
$notify .= 'position: "'.$position.' ",';
$notify .= 'closeTimeout: "'.$closeTimeout.' ",';
$notify .= 'showProgress: "'/span>.$showProgress.'",';
$notify.= '});</script>';
return $notify;
}
//呼叫它。
$flash = [];
$flash[] = $this-> Notification-> build('error'/span>, 'Test'/span>, 'danger'/span>, 'bottom-left', 0, 'true')。)
$flash[] = $this-> Notification-> build('error', 'Test1', 'danger', 'bottom-left', 0, 'true')。)
$this->Session->setFlashData("notice", $flash) 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/319155.html
標籤:
上一篇:如何修復:"@angular/fire"'沒有匯出成員'AngularFireModule'.ts(2305)ionic,firebase,angul
