重定向到主页 cakephp 3
Redirect to a homepage cakephp 3
我按照 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'));
我的问题是,如何将它重定向到主页。我完全按照网站上的教程进行了操作。
看起来 "license header" 行应该是注释,但不在 <?php ?>
标记内,因此被视为输出。如果是这种情况,已经生成一些输出的事实将阻止重定向发生。
您只需要在controller 属性中指定controller 名称,在action 属性中指定action 名称。
$this->redirect(['Controller' => 'Homepage Controller name' , 'action' => 'homepafe action name']);
成功后它将重定向到您提到的位置。
我按照 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'));
我的问题是,如何将它重定向到主页。我完全按照网站上的教程进行了操作。
看起来 "license header" 行应该是注释,但不在 <?php ?>
标记内,因此被视为输出。如果是这种情况,已经生成一些输出的事实将阻止重定向发生。
您只需要在controller 属性中指定controller 名称,在action 属性中指定action 名称。
$this->redirect(['Controller' => 'Homepage Controller name' , 'action' => 'homepafe action name']);
成功后它将重定向到您提到的位置。