首页 > 解决方案 > 从 cakphp 表单操作中删除 id

问题描述

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

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

标签: cakephp

解决方案


例如,如何让用户只编辑自己的用户帐户而不在 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'));
}

推荐阅读