Javascript Cakephp和Sweet Alert
我有一个关于cakephp和sweet alert的问题。 您是否能够替换标准的Flash消息,而不是发出Sweet Alert?我已经设法向Sweet Alert发出删除记录的确认,但我不知道在它保存数据(例如在edit.ctp中)时如何处理它,保存后会将我带到index.ctp(这里我希望Sweet跳转弹出) 在确认移除时,我使用了falco442的cakephp-3-sweet-alert-helper 这是我的编辑方法:Javascript Cakephp和Sweet Alert,javascript,php,jquery,cakephp,sweetalert,Javascript,Php,Jquery,Cakephp,Sweetalert,我有一个关于cakephp和sweet alert的问题。 您是否能够替换标准的Flash消息,而不是发出Sweet Alert?我已经设法向Sweet Alert发出删除记录的确认,但我不知道在它保存数据(例如在edit.ctp中)时如何处理它,保存后会将我带到index.ctp(这里我希望Sweet跳转弹出) 在确认移除时,我使用了falco442的cakephp-3-sweet-alert-helper 这是我的编辑方法: public function edit($id = null)
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(“您的成功消息”)有来自SWAL的警报?您应该保持控制器代码不变 但是您应该在
src/Template/Element/flash/
更新flash消息模板
默认情况下,CakePHP输出
,您应该将其替换为swal(“Hello world!”)代码>您可以在此处设置sweet alert javascript
路径:src/Template/Element/Flash
success.ctp
error.ctp
首先要使用sweet alert js和css
游泳({
标题:“成功”,
文本:“已成功创建”,
图标:“成功”,
});
好的,谢谢。这是工作。我忘了将$this->Flash->render()添加到default.ctp