[英]How to use sweetalert in cakePHP
我正在使用 cakphp4。 我有一個關於 cakephp 和甜蜜警報的問題。 我們可以用 sweetalert 替換標准的 flash 消息嗎? (我的意思是代替標准的 Flash 消息,發出甜蜜警報?)
用戶控制器.php
public function delete($slug)
{
$this->request->allowMethod(['post', 'delete']);
$user = $this->Users->findBySlug($slug)->firstorFail();
if ($this->Users->delete($user)) {
$this->Flash->success("Deleted Successfully");
return $this->redirect(['action' => 'index']);
}
$this->Flash->error('Unable to Delete user');
return $this->redirect(['action' => 'index']);
}
模板/元素/flash/success.php
<?php
if (!isset($params['escape']) || $params['escape'] !== false) {
$message = h($message);
}
?>
<div class="message success" onclick="this.classList.add('hidden')">
<?= $message ?></div>
您可以查看Flash 組件的文檔。 您要更改的部分是您可以在templates/element/flash
找到的模板:
// Uses templates/element/flash/success.php
$this->Flash->success('This was successful');
// Uses templates/element/flash/great_success.php
$this->Flash->greatSuccess('This was greatly successful');
你有這個訂單項
<?= $this->Flash->render() ?>
在默認布局中,顯示每條 flash 消息(基於他上面回答中提到的模板)。
您可以獲取結果並將其用作 sweetalert 的輸入,而不是回顯它。
<?php $inputForSweetAlert = $this->Flash->render(); ?>
答案未經測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.