2016-07-18 4 views
0

Я хочу перенаправить на то, что я только что ввел в своей статье. Но, похоже, идентификатор не доступен как-то ...Перенаправление после создания входа в Cakephp 3

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 \ Таблица \ ArticlesTable" не связан с " id "

ответ

0

К сожалению, вам нужно сохранить функцию сохранения в переменной. Затем он работает:

if ($this->Articles->save($tmp = $data, array('deep' => true))) { 
           $current_id = $tmp->id; 
           return $this->redirect(['controller'=> 'articles', 'action' => 'view', $current_id]);     
          } 
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]); 
} 
0

U можете попробовать это:

$article = $this->Articles->newEntity($this->request->data); 
if ($this->request->is('post')) { 
    $article = $this->Articles->patchEntity($article, $this->request->data); 
    if ($this->Articles->save($article, array('deep' => true))) { 
     $id = $article->id; 
     return $this->redirect(array('action' => 'view',$id));    
    } 
} 
Смежные вопросы