We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Success Delete but data no delete

public function deleteAction()
    {

        $siteId =$this->getSite(); 

        $request = new Request();
        $Id ="contactNo";

        if ($request->isPost()) {
            if ($request->isAjax()) {
            //echo 'Request was made using POST and AJAX';
                $request = new Request();
                $Id = $request->getPost("contactNo");
        }
        }

        if(empty($Id))
        {
            return;
        }

        $binddata = 
        [   
            'SiteId'=>$siteId,
            'contactNo' => $Id
        ];

        $Contact = Contact::findfirst(
            [
                'columns' => ['*'],
                'conditions' =>'SiteId = :SiteId: and Id = :Id: ',
                'bind' => $binddata
            ]
        );

        if( $Contact !=null)
        {
            $Contact->ExpireDate = date('Y-m-d H:i:s');

            if (!$Contact->delete()) {
                foreach ($Contact->getMessages() as $message) {                     
                        $this->flash->error('contact '.$message);  
                }
            // echo 'Data saving is failed..!'; 
            }
        }
    }

Help to fix my project.



1.1k
edited Mar '18

Looks like your binddata is incorrect?

'conditions' =>'SiteId = :SiteId: and Id = :Id: ',

should be

'conditions' =>'SiteId = :SiteId: and Id = :contactNo: ',


1.8k

The same. The data is not deleted



70
  1. Is $Contact null or not ?
  2. Maybe $Contact return is array object. you need delete by element of array