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

Collection delete() not found

Hello, help please

Portfolio model

use Phalcon\Mvc\Collection; class Portfolio extends Collection { public $name; public $content; public $status; }

Portfolio controller

use Modules\Admin\Models\Portfolio; class Portfolio extends Collection { public function removePortfolio() { $this->view->disable(); $portfolio = Portfolio::findFirst(array( array("_id" => $this->request->getPost("id")) )); if ($portfolio->delete() == false) { $r = "fail"; } else { $r = "done"; } die($r); } }

I get an error Fatal error: Call to a member function delete() on boolean save () works, delete () is not! help solve the problem



58.4k

Hey

You try code test it

$robot = Portfolio::findFirst();
if ($robot != false) {
    if ($robot->delete() == false) {
        echo "Sorry, we can't delete the robot right now: \n";
        foreach ($robot->getMessages() as $message) {
            echo $message, "\n";
        }
    } else {
        echo "The robot was deleted successfully!";
    }
}