Necessito de obter o id
do link presente no método postLink
para poder apagar da base de dados uma imagem cujo id
seja igual a esse id do link, que é igual ao id da base de dados.
Como faço para obter esse valor?
View
<h2>Apagar Fotografia</h2>
<br>
<table border="1" bordercolor="#e2e2e2" width="720" style="word-wrap: break-word">
<tr>
<?php
$i=0;
foreach( $gallery_images as $gallery_image ):?>
<?php
echo "<td style=text-align: justify>";
//echo $gallery_image['GalleryImage']['path'];
echo $this->Form->postLink('Apagar Fotografia', array('controller'=>'Gallery', 'action'=>'admin_del_image', $gallery_image['GalleryImage']['id'],/*'prefix'=>'admin'*/), array('class'=>'foto_del', 'title'=>'Apagar Fotografia'), __('Tem a certeza que quer apagar esta Fotografia?'));
echo "</td>";
echo "<td>";
//$src3 =$this->webroot. 'img/gallery/' .$gallery_image['GalleryImage']['path'];
echo $this->Html->image('gallery/' . $gallery_image['GalleryImage']['path'] , array('width' => '200px', 'height' => '133px', 'alt' => $gallery_image['GalleryImage']['path'] ));
echo "</td>";
$i++;
if($i==2){
echo "</tr><tr>";
$i=0;
}
?>
<?php endforeach ?>
</tr>
Controller
public function admin_del_image(){
$this->layout = 'admin_index';
$this->loadModel('GalleryImage');
$this->GalleryImage->id=$id;
$gallery_images = $this->GalleryImage->find('all');
$this->set('gallery_images', $gallery_images);
if($this->request->is('post')){
if(!$this->GalleryImage->exists()){
throw new NotFoundException(__('Fotografia inválida'));
}
//$this->request->onlyAllow('post','delete');
$options = array('conditions' => array('GalleryImage.' .$this->GalleryImage->primaryKey=>$id));
$gallery_image_delete=$this->GalleryImage->find('first', $options);
if(file_exists(WWW_ROOT. "img/gallery/" .$gallery_image_delete['GalleryImage']['path'])){
unlink(WWW_ROOT . "img/gallery/" .$gallery_image_delete['GalleryImage']['path']);
$this->GalleryImage->delete();
$this->Session->setFlash(__('Fotografia excluída com sucesso'));
}
else{
$this->Session-setFlash(__('ERRO!, esta Fotografia não existe'));
}
$this->redirect($this->refere());}
}
Output
<td style="text-align:" justify=""><form action="/html/PushUp_app/Gallery/admin_del_image/25" name="post_5330531636e39982291469" id="post_5330531636e39982291469" style="display:none;" method="post"><input type="hidden" name="_method" value="POST"></form><a href="#" class="foto_del" title="Apagar Fotografia" onclick="if (confirm("Tem a certeza que quer apagar esta Fotografia?")) { document.post_5330531636e39982291469.submit(); } event.returnValue = false; return false;">Apagar Fotografia</a></td>
<td><img src="/html/PushUp_app/img/gallery/PushUp.png" width="200px" height="133px" alt="PushUp.png"></td>