i just forgot to add enctype="multipart/form-data" in form tag
i can update name
.price
etc. but i don't know how to update image.
sharing my code for upload and edit.
Controller code for Upload product
public function products()
{
$this->loadModel("Product");
$this->loadModel("Subcat");
if(isset($this->request->data["b1"]))
{
$fn=time().$this->request->form['photo']['name'];
$filename=WWW_ROOT.DS.'images'.DS.'product'.DS.$fn;
move_uploaded_file($this->request->form['photo']['tmp_name'],$filename);
$this->request->data["photo"]=$fn;
if($this->Product->save($this->request->data))
{
$this->Session->setFlash('Successully save your information!');
}
}
$this->loadModel("Addcat");
$dt=$this->Addcat->find('list',array('fields'=>array('id','cat_name')));
$this->set('drop',$dt);
$this->loadModel("Subcat");
$dt1=$this->Subcat->find('list',array('fields'=>array('id','sub_cat')));
$this->set('drop1',$dt1);
$this->loadModel("Brand");
$dt2=$this->Brand->find('list',array('fields'=>array('id','name')));
$this->set('drop2',$dt2);
$this->loadModel("Product");
$this->layout="adminindex";
if(isset($this->request->query["action"]))
{
if($this->request->query["action"]=="delete")
{
$this->Product->delete($this->request->query["id"]);
}
}
$data = $this->Product->find('all');
$this->set('product',$data);
}
Controller code for edit product
public function editproduct()
{
$this->loadModel("Product");
$this->layout="adminindex";
if(isset($this->request->query["id"]))
{
$data = $this->Product->findByid($this->request->query["id"]);
$this->set('product', $data);
}
if(isset($this->request->data["b1"]))
{
$fn=time().$this->request->form['photo']['name'];
$filename=WWW_ROOT.DS.'images'.DS.'product'.DS.$fn;
move_uploaded_file($this->request->form['photo']['tmp_name'],$filename);
$this->request->data["photo"]=$fn;
$this->Product->updateAll(
array("name"=>"'".$this->request->data["name"]."'",
"price"=>"'".$this->request->data["price"]."'",
"photo"=>"'".$this->request->data["photo"]."'",
"product_description"=>"'".$this->request->data["product_description"]."'"),
array('id'=>$this->request->data["id"]));
$this->redirect("../admin/products");
}
}
View for edit product
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="add category-form">
<h2>Edit Product!</h2>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $product["Product"]["id"]?>">
<table>
<tr>
<td>Name</td>
<td><input type="text" name="name" value="<?php echo $product["Product"]["name"]?>"></td>
</tr>
<tr>
<td>Price</td>
<td><input type="text" name="price" value="<?php echo $product["Product"]["price"]?>"></td>
</tr>
<tr>
<td>Photo</td>
<td><input type="file" name="photo" value="<?php echo $product["Product"]["photo"]?>"></td>
</tr>
<tr>
<td>Product Description</td>
<td><input type="text" name="product_description" value="<?php echo $product["Product"]["product_description"]?>"></td>
</tr>
<tr>
<td><button type="submit" class="b1" name="b1">Update</button></td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>