从cakphp表单操作中删除ID

时间:2018-11-08 07:39:09

标签: cakephp

<form id="RecipeEditForm" method="post" action="/recipes/edit/5">

我需要从表单操作中删除/ 5,该怎么办。 我正在使用Cakephp 3。

1 个答案:

答案 0 :(得分:0)

例如,如何使用户仅编辑自己的用户帐户而无需在url中传递id。

public function edit()
{
    $user = $this->Users->find()
        ->where(['id' => $this->Auth->user('id')])
        ->firstOrFail();

    if ($this->request->is(['patch', 'post', 'put'])) {
        $user = $this->Users->patchEntity($user, $this->request->getData());
        if ($this->Users->save($user)) {
            /$this->Flash->success(__('The user has been saved.'));

            return $this->redirect(['action' => 'index']);
        }
        $this->Flash->error(__('The user could not be saved. Please, try again.'));
    }
    $this->set(compact('user'));
}