【问题标题】:Cakephp and Sweet AlertCakephp 和甜蜜警报
【发布时间】:2023-03-20 18:00:01
【问题描述】:

我有一个关于 cakephp 和 sweet alert 的问题。 您是否能够替换标准的 Flash Message,而不是提供 Sweet Alert?我已经设法给 Sweet Alert 确认删除记录,但我不知道在它保存数据时如何处理它(例如在 edit.ctp 中),保存后将我带到 index.ctp(这里我想要 Sweet Jump 弹出)。

在确认删除时,我使用了 falco442cakephp-3-sweet-alert-helper

这是我的编辑方法:

public function edit($id = null)
{
    $contact = $this->Contacts->get($id, [
        'contain' => ['Users', 'Departments']
    ]);
    if ($this->request->is(['patch', 'post', 'put'])) {
        $contact = $this->Contacts->patchEntity($contact, $this->request->getData());
        if ($this->Contacts->save($contact)) {
            $this->Flash->success('Contact saved');

            return $this->redirect(['action' => 'index']);
        }
        $this->Flash->error(__('The contact could not be saved. Please, try again.'));
    }
    $users = $this->Contacts->Users->find('list', ['limit' => 200]);
    $this->set(compact('contact', 'users'));
}

如何将这个 $this->Flash->success('Your Success Message.'); 替换为来自 SWAL 的警报?

【问题讨论】:

    标签: javascript php jquery cakephp sweetalert


    【解决方案1】:

    您应该保持控制器代码不变。

    但您应该在src/Template/Element/Flash/ 更新 Flash 消息模板。

    默认情况下,CakePHP 输出<div>,您应该将其替换为<script>swal("Hello world!");</script>

    【讨论】:

    • 好的,谢谢。是工作。我忘记将 $this->Flash->render() 添加到 default.ctp
    【解决方案2】:

    在这里你可以设置甜蜜警报 javascript

    路径:src/Template/Element/Flash 成功.ctp 错误.ctp

    首先使用甜蜜警报 js 和 css 狼吞虎咽({ 标题:“成功”, text: "创建成功", 图标:“成功”, });

    【讨论】:

      猜你喜欢
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-02
      • 2017-01-04
      • 1970-01-01
      相关资源
      最近更新 更多