在Cakephp 3中创建Entry后重定向

时间:2016-07-18 12:36:13

标签: cakephp redirect

我想重定向到我刚刚在文章中输入的内容的视图。但它似乎无法以某种方式获得...

if ($this->Articles->save($data, array('deep' => true))) {
                                $current_id = $this->Articles->id;
                                return $this->redirect(['controller'=> 'articles', 'action' => 'view', $current_id]);                
                            }

我刚收到 502 Bad Gateway  有时候也会:

表" App \ Model \ Table \ ArticlesTable"与" id"

无关

2 个答案:

答案 0 :(得分:0)

您必须将保存功能保存在变量中。然后它工作:

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        loadUrl("javascript:native_callback()");
    }
}, 0);

答案 1 :(得分:0)

我认为正确的代码是

$article= $this->Articles->newEntity($data);
if ($this->Articles->save($article, array('deep' => true))) {
    $current_id = $article->id;
    return $this->redirect(['controller'=> 'articles', 'action' => 'view', $current_id]);
}