Question

I have a small problem. I have a table item_pictures that has 6 fields img1 | img2 | img3 | ima4 | img5| that store 5 images. so it means one row of Batabases has 5 fields that store the path of the images. What i wanna do is that to create kind of a button next to each image that when the user click it, it just update the field of the image making it empty, thats all i want. So that all i want to update or change only one speciffic field. is that possible and if so how??

Thats the code i have comme up so far:

$this->Form->postLink($this->Html->tag('i', '', 
                array('class' => 'glyphicon glyphicon-remove')),
                array('controller' => 'item_pictures','action' => 'delete_current_img', $item['Item']['id'] .'-'. 'img'.$i .'-'. $pictures['img'.$i]) ,
                array('escape' => false), __('Are you sure you want to delete This Image?'))

So i want that in the controller to grab this variable and to update the row with the id => $item['Item']['id'] , on the column img.$i with the value $pictures['img'.$i], and make it empty...

Was it helpful?

Solution

I think you were pretty close, so I would cycle $i = 1 to $i = 5 with

$item_picture_id = $item['Item']['ItemPicture']['id'] //or something, im not sure how you have done your relations

echo $this->Form->postLink($this->Html->tag('i', '',
    array('class' => 'glyphicon glyphicon-remove')),
    array('controller' => 'item_pictures','action' => 'delete_current_img', $item_picture_id, 'img'.$i) ,
    array('escape' => false), __('Are you sure you want to delete This Image?'));

So for example image 5 ($i = 5) should resolve to the URL: item_pictures/delete_current_img/ID/img5/

Then for your controller just have (very simple example):

public function delete_current_img($id,$field){
    $this->ItemPicture->id = $id;
    $this->ItemPicture->saveField($field,'');
    //then just go back to where you come from
    $this->redirect(array('controller' => 'foo', 'action' => 'where_ever_the_delete_came_from'));
}

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top