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

Need a flow with crude operation

Dear Team,

  • As I am new so can you please give me link for demo code of phalcon for crud operation.

Thanks

edited Aug '14

Hi naveengujri,

Phalcon works with the MVC pattern, meaning that almost everything you'll do to interact with databases will happen in the "Model". Just setup your connection in index.php, for example:

        // Setup the database component.
        $di->set('db', function() use ($config) {

            // Create connection.
            $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
                "host" => $config->database->host,
                "username" => $config->database->username,
                "password" => $config->database->password,
                "dbname" => $config->database->dbname,
                'persistant' => $config->database->persistant,
                'charset' =>'utf8'
            ));

            // Return connection.
            return $connection;

        });

Then create your models, you can read more about them here: https://docs.phalcon.io/en/latest/reference/models.html You than have access to several CRUD methods, for example ->save(), ->find(), ->findFirst(), ->delete(), etc. on your model.

Hope this helps!