我在 cakephp 中有函数使用 ajax 和 jQuery 我将总和数据发送到我的视图和总和链接,如编辑和删除,但我无法发送删除链接
如何在我的控制器中创建链接删除
代码控制器
function recherche($desi=null,$test=null)
{
if($desi!=null || $test!=null )
{
$this->Materiel->recursive = -1;
$produits=$this->Materiel->find('all',array('conditions' => array("Materiel.name LIKE '%$desi%'")));
echo '<table>';
echo '<tr>
<th>Designation</th>
<th>Prix de vente</th>
<th>Prix de Fornisseurs</th>
<th>Stock</th>
<th>quantité d\'alerte</th>
<th>Action</th>
</tr>';
foreach ($produits as $produit)
{
$id=$produit['Materiel']['id'];
echo "<tr>";
echo "<td><ck id=d$id>".$produit['Materiel']['name']."</ck></td>";
echo "<td><ck id=p$id>".$produit['Materiel']['prix']."</ck> DH</td>";
echo "<td><ck id=p$id>".$produit['Materiel']['prixf']."</ck> DH</td>";
echo "<td><ck id=s$id>".$produit['Materiel']['quantite']."</ck></td>";
echo "<td><ck id=p$id>".$produit['Materiel']['souille']."</ck></td>";
echo "<td><a href='/hossam/materiels/edit/".$produit['Materiel']['id']."'>Editer</a></td>";
echo '</tr>';
}
echo '</table>';
exit();
}
}
代码视图
<?php
echo $this->Html->script('ajax');
?>
<div class="materiels form">
<?php echo $this->Form->create('Materiel');?>
<fieldset>
<legend>
<?php echo __('Recherche Produit'); ?>
</legend>
<label for="MaterielCategories">Recherche par Designation</label>
<input type="text" id="produit1">
<div id="sites">
</div>
</fieldset>
</div>
代码 ajax.js
$("#produit1").keyup(function() {
var id=$("#produit1").val();
var image="<center><img src='/hossam/img/loading.gif' style='width: 180px;' ></center>";
$("#sites").empty();
$(image).appendTo("#sites");
$("#sites").show();
$.post(
'/hossam/materiels/recherche/'+id+'/1',
{
//id: $("#ChembreBlocId").val()
},
function(data)
{
$("#sites").empty();
$(data).appendTo("#sites");
$("#sites").show();
},
'text' // type
);
});
代码链接删除
<?php echo $this->Form->postLink(__('Supprimer'), array('action' => 'delete', $user['User']['id']), null, __('Are you sure you want to delete # %s?', $user['User']['id'])); ?>