【发布时间】:2015-09-06 06:36:07
【问题描述】:
我已经按照 cakephp 3 网站上的文章教程创建了网站
http://i.imgur.com/JMh1Pwv.png
现在有添加文章、删除文章和编辑文章操作。
当我删除一篇文章时,它会将我重定向到
http://localhost:8888/test/articles/delete/14
这是删除代码。
public function delete($id) {
$this->request->allowMethod(['post', 'delete']);
$article = $this->Articles->get($id);
if ($this->Articles->delete($article)) {
$this->Flash->success(__('The article with id: {0} has been deleted.', h($id)));
return $this->redirect(['action' => 'index']);
}
}
添加和编辑也是如此。
现在它停留在那个空白页上(http://i.imgur.com/TdcbxZZ.png)。但是return $this->redirect(['action' => 'index']); 行假设将其重定向到主页,即在索引上
在 routes.php 中,我将路由定义为
Router::connect('/', array('controller' => 'Articles', 'action' => 'index'));
我的问题是,如何将其重定向到主页。我完全按照网站上的教程进行操作。
【问题讨论】:
-
很有可能不会发生删除。尝试为您的
if添加else并调试您到达那里的原因。无论如何,如果你打开调试,你会看到会发生什么。另一方面,$this->redirect('/')会将您重定向到家。 -
@rrd 项目被删除。我试过 ` $this->redirect('/') ` 但结果相同。
-
@summea 当然。这里是pastebin.com/1gT6Fj9p
-
粘贴时出错。在原始文件上它不存在。如果将 / 放在第 54 行,Netbeans 会出错。
-
@summea 谢谢,我会尝试并告诉你。
标签: php redirect routes cakephp-3.0