简体   繁体   English

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

[英]i cant pass the parameter id on the URI slim framework

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){ 公共功能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. 但是当我手动添加ID时,它可以工作并重定向回admin.product。

please help me im getting stuck for about 4 days and i need this for my college task 请帮助我被卡住约4天,我需要此来完成我的大学课程

Slim also uses Restful URLs it seems. Slim似乎也使用Restful URL。 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. 当您在表单中将_method设置为“ put”并发送请求时,它将把它解释为PUT请求而不是GET。 Since this is your college task, I think I've helped you with 99% of the problem here. 由于这是您的大学任务,因此我想为您解决了99%的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM