簡體   English   中英

Zend Db表刪除不起作用

[英]Zend Db Table delete not working

我是zend Framework的新手,想從數據庫中刪除數據,但刪除功能不起作用。 請幫幫我。

這是我的控制器代碼。

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);

    }

    }

這是我的模型代碼。

public function deleteClient($id)
{

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

這是我的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>

我知道問題出在哪里

您正在使用 ,

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

對於$id$del所以如果您說的是$ id = 1,那么$ del =“ yes”將不是真的!

因此,請嘗試為您的視圖腳本中的$ del或測試袋傳遞不同的ID,只需暫時刪除該條件即可。

嘗試通過是這樣的否按鈕,

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

然后使用

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

更新 *

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

希望這可以幫助..

請嘗試以下代碼:

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