cakePHP(v3.x)を使ってeditページをするときは以下の三つを行いましょう。
ルートの設定
ここで
https://hogehoge.jp/articles/
routes.php
$routes->connect('/articles/:id/edit',
['controller' => 'Articles', 'action' => 'edit'],
['id' => '\d+', 'pass' => ['id']]
);
Controllerの設定
次にControllerの設定を行いましょう。先ほどのルートの設定でedit関数にidを渡すようにしたのでそれにしたがって
/Controller/ArticlesController.php
public function edit($id = null)
{
$login_user_id = $this->Auth->user('id');
$article = $this->Articles->get($id);
if ($this->request->is('post')) {
$postData = $this->request->getData();
$postData['user_id'] = $login_user_id;
$article = $this->Articles->patchEntity($article, $postData);
if ($this->Billings->save($article)) {
$this->Flash->success(__('The article has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The article could not be saved. Please, try again.'));
}
$this->set(compact('article'));
$this->render('edit');
}
このように編集します。
edit.ctpの設定
こちらはAddをする処理時と特に違いはありません。
<?php
<!-- File: src/Template/Articles/edit.ctp -->
<h1>Edit Article</h1>
<?php
echo $this->Form->create($article);
echo $this->Form->control('title');
echo $this->Form->control('body', ['rows' => '3']);
echo $this->Form->button(__('Save Article'));
echo $this->Form->end();
?>


