简体   繁体   English

Zend Db表删除不起作用

[英]Zend Db Table delete not working

I am new to zend framework and want to delete data from database, but delete function is not working. 我是zend Framework的新手,想从数据库中删除数据,但删除功能不起作用。 Please help me out. 请帮帮我。

Here bis my controller code. 这是我的控制器代码。

public function deleteAction()
{

    if($this->getRequest()->isPost())
    {

        $del= $this->getRequest()->getPost('id');

        if($del=="Yes")
        {
            $id =$this->getRequest()->getpost('id');

        $client = new Application_Model_DbTable_Client();
        $id = $this->getrequest()->getparam('id');
        $client->deleteClient($id);

      }
     $this->_helper->redirector('index');
   }
    else
    {
       $id = $this->getRequest()->getparam('id');

       $client   = new Application_Model_DbTable_Client();
       $this->view->client = $client->getclient($id);

    }

    }

Here is my model code. 这是我的模型代码。

public function deleteClient($id)
{

     $this->delete('Id='.(int)$id);
}

Here is my delete.phtml file. 这是我的delete.phtml文件。

<form>
<p>Are you sure that you want to delete


<?php foreach($this->client as $clients): ?>
'<?php echo $this->escape($clients['firstname']); ?>'
'<?php echo $this->escape($clients['lastname']); ?>'
'<?php echo $this->escape($clients['email']); ?>'
 </p>
 <?php endforeach; ?>
<form action="<?php echo $this->url(array('action'=>'delete')); ?>" method="post">
<div> 

<input type="hidden" name="id" value="<?php echo $this->escape($clients["Id"]); ?>"/>

<input type="submit" name="del" value="Yes" />
<input type="submit" name="del" value="No" />

</div>

</form>

i see where the problem is, 我知道问题出在哪里

you are using , 您正在使用 ,

$this->getRequest()->getPost('id');

for both $id AND $del so if you are getting $id=1 as you are saying then $del="yes" will not be true! 对于$id$del所以如果您说的是$ id = 1,那么$ del =“ yes”将不是真的!

so try to pass different id for $del in your view script or for the testing sack just remove that condition temporally.. 因此,请尝试为您的视图脚本中的$ del或测试袋传递不同的ID,只需暂时删除该条件即可。

try to pass the yes no buttons like this, 尝试通过是这样的否按钮,

<input type="submit" class="btn-glow primary" name="del" value="Yes" />
<input type="submit" class="btn" name="del" value="No" />  

then use 然后使用

 $del = $this->getRequest()->getPost('del');

update * 更新 *

<input type="hidden" name="id" value="<?php echo $this->client['id'];?>"/>

Hope this Helps.. 希望这可以帮助..

Please try below code : 请尝试以下代码:

public function deleteClient($id)
{
  $this->dbAdapter->delete('table_name','Id='.(int)$id);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM