控制器cakephp中的链接删除
我在cakephp中有一个函数,使用ajax和jQuery,我将总和数据发送到我的视图和总和链接,比如编辑和删除,但我不能发送用于删除的链接 如何在控制器中创建链接删除 代码控制器控制器cakephp中的链接删除,php,ajax,jquery,cakephp,Php,Ajax,Jquery,Cakephp,我在cakephp中有一个函数,使用ajax和jQuery,我将总和数据发送到我的视图和总和链接,比如编辑和删除,但我不能发送用于删除的链接 如何在控制器中创建链接删除 代码控制器 function recherche($desi=null,$test=null) { if($desi!=null || $test!=null ) { $this->Materiel->recursive = -1; $produits=$this-&g
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();
}
}
函数recherche($desi=null,$test=null)
{
如果($desi!=null | |$test!=null)
{
$this->materials->recursive=-1;
$produits=$this->materials->find('all',array('conditions'=>array(“material.name,如“%$desi%”));
回声';
回声'
任命
文特大奖赛
弗尼瑟斯大奖赛
股票
数量警报
行动
';
foreach($produit作为$produit)
{
$id=$produit['materials']['id'];
回声“;
echo“$produit['materials']['name']”;
echo“$produit['materials']['prix'].”DH;
echo“$produit['materials']['prixf'].”DH;
echo“$produit['materials']['quantite']”;
echo“$produit['materials']['souille']”;
回声“;
回声';
}
回声';
退出();
}
}
代码视图
<?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
);
});
$(“#produit1”).keyup(函数(){
var id=$(“#produit1”).val();
var image=“”;
$(“#站点”).empty();
$(图)。附加到(“站点”);
$(“#站点”).show();
美元邮政(
“/hossam/materials/recherche/”+id+“/1”,
{
//id:$(“#ChembreBlocId”).val()
},
功能(数据)
{
$(“#站点”).empty();
$(数据)。附于(“#站点”);
$(“#站点”).show();
},
'text'//类型
);
});
代码链接删除
<?php echo $this->Form->postLink(__('Supprimer'), array('action' => 'delete', $user['User']['id']), null, __('Are you sure you want to delete # %s?', $user['User']['id'])); ?>
不要直接在控制器中“回显”。为“recherche”定义一个视图并在那里进行打印。您可以使用表单帮助器并创建删除链接
如果您仍然希望在控制器本身中执行“echo”,那么有两件事可以做
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
<form action="/hossam/materiels/delete/1" style="display:none;" method="post" name="post_5271088279c63" id="post_5271088279c63">
<input type="hidden" name="_method" value="POST">
</form>
<a href="#" onclick="if (confirm('Are you sure you want to delete # 1?')) { document.post_5271088279c63.submit(); } event.returnValue = false; return false;">Delete</a>
所以你必须回应上面的内容,而不是编辑链接