cakephp - 从 cakphp 表单操作中删除 id
问题描述
<form id="RecipeEditForm" method="post" action="/recipes/edit/5">
我需要从表单操作中删除 /5 我该怎么做。我正在使用 Cakephp 3。
解决方案
例如,如何让用户只编辑自己的用户帐户而不在 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'));
}
推荐阅读
- javascript - 获取数组值并添加它们(如果它们是数字)
- ruby-on-rails - 部署 Rails 应用程序,无法命中端点
- php - 公共函数__construct致命错误:未捕获错误:找不到类
- python-3.x - 如何在 tkinter 中刷新屏幕以显示新的标签文本?
- angular - 如何在样式规则中使用带有插值的 ngStyle
- mysql - 如何将一行的多列总和存储在同一张表的同一行的另一列上?
- reactjs - Reactjs:如何在生产应用程序的 devtools 中隐藏节点模块和 webconfig?
- java - 从用户那里获得五个输入的最大值和最小值
- java - 主要/次要对角线和行未在连接四个项目中注册为胜利
- java - 异步 servlet 如何在不打开更多线程的情况下保持与 http 客户端的连接