我試圖清除閃爍留言CakePHP中3.1.1清除閃爍留言CakePHP中3.1.1
我有一個功能,當用戶登錄時,如果他的客戶資料不完整,他被重定向以一種形式來完成它。看起來像這樣:
public function index()
{
//Some code to check whether the customers profile is complete
//If it's not complete, then redirect to the "complete" action with a flash message
if($completion == 0){
$this->Flash->success(__('Please complete your customer profile data.'));
$this->setAction('complete', $custid);
//Otherwise go to their view
} elseif ($completion == 1){
$this->setAction('view', $custid);
}
}
這工作正常,並且用戶被重定向到Flash消息的完整操作/表單。
然後將整個動作看起來是這樣的:
public function complete($id = null)
{
//Get all the customer data input
if ($this->request->is(['patch', 'post', 'put'])) {
$customer = $this->Customers->patchEntity($customer, $this->request->data);
//Set the completion status to complete (1)
$customer->completion_status = 1;
if ($this->Customers->save($customer)) {
$completion = 1;
$this->set('completion', $completion);
//After the Save, redirect to the View action with a new Flash Message
$this->Flash->set(__('Your customer information is complete and has been saved!',['clear'=>'true']));
return $this->redirect(['action' => 'view',$custid]);
} else {
$this->Flash->error(__('The customer could not be saved. Please, try again.'));
}
}
$this->set(compact('customer'));
$this->set('_serialize', ['customer']);
}
它工作正常,但:保存自己的數據後,當用戶被重定向到與成功的Flash的瀏覽動作,Flash的指數(告訴他們'請填寫您的客戶資料數據')仍會再次顯示。
如果用戶在視圖上刷新,則兩個Flash消息都應該消失。
如何在重定向時清除最初的Flash消息?我試過使用清除鍵,但它似乎不工作。
任何意見非常感謝! 謝謝, DBZ
感謝您的回覆。但是,這些給我的錯誤:「調用一個非對象的成員函數delete()」。 – dividedbyzero
此外,當在調試模式下,會話Flash變量顯示爲空....不知道爲什麼這是... – dividedbyzero
在cake3其$ this-> request-> session() - >刪除 –