Check if content exist in database


I'm currently converting my project to Phalcon PHP. In my old project I did a if to check if the conetnt I'm pulling from a API exist in a database, if it didn't I would add it to the DB and display the fresh content I just got from the API.

How could I do something similar to this with Phalcon?


See this for working with models

// (..) => Inside put the binding params.
$apiContent = ApiContent::findFirst(..);

// If it is false, there isn't such record in the table. Then we prepare it to insert in the DB.
if (!$apiContent)
    $apiContent = new ApiContent();

    // Here do SETs.

    if ($apiContent->create()) // or '$apiContent->save()'.
        // Set $apiContent to what do you want to display. This can be setting the var in the view, for example.
        // Throw an exception, show a message error, etc.