dongtan8532 2017-04-16 02:22 采纳率: 0%
浏览 53

我无法在URI slim框架上传递参数id

i have an update form to update the product details :

<form action="{{ path_for('product.update', {id: product.id}) }}" method="get">
// another fields
<input type="hidden" name="_METHOD" value="PUT">
<input type="submit" name="submit" class="submit" value="update">

routes :

$app->get('/admin/product/edit/{id}', ['maimana\Controllers\AdminController','editupdateProduct'])->setName('product.edit');
$app->get('/admin/product/update/product/{id}', ['maimana\Controllers\AdminController','updateProduct'])->setName('product.update');

and the controller :

public function updateProduct($id, Request $request, Response $response){

  $product = $this->product->where('id',$id)->first()->update([
    'title' => $request->getParam('title'),
    'category' => $request->getParam('category'),
    'slug' => $request->getParam('slug'),
    'description' => $request->getParam('description'),
    'price' => $request->getParam('price'),
    'image' => $request->getParam('image'),
    'stock' => $request->getParam('stock')
  ]);

  return $response->withRedirect($this->router->pathFor('admin.product'));


}

everytime i hit the update button, i cant pass the parameter is automatically and it turns PAGE NOT FOUND. but when i add the id manually it works and redirect back to admin.product.

please help me im getting stuck for about 4 days and i need this for my college task

  • 写回答

1条回答 默认 最新

  • dongzhong2018 2017-04-16 05:19
    关注

    Slim also uses Restful URLs it seems. When you have the _method set to 'put' in the form and sends the request, it will interpret it as a PUT request rather than a GET. Since this is your college task, I think I've helped you with 99% of the problem here.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式