Book Image

Learning Phalcon PHP

Book Image

Learning Phalcon PHP

Overview of this book

Table of Contents (17 chapters)
Learning Phalcon PHP
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

ODM/MongoDB


We will not discuss ODM too much. It mostly supports the same actions as ORM. CRUD operations can be done in the same way as we did with ORM. Of course, we can't use transactions here, since MongoDB is not a transactional database.

Another important thing is that we need to declare the variables as public, not protected, as we did with the article model. This is the case in Phalcon version 1.3.4, but maybe in version 2.0, things will change.

A big difference is in the parameters that we pass to a find() method. Suppose we used something like the following code for ORM:

Article::find([
    'article_slug' => 'test-article-title'
]);

For the ODM, we need to do it like this:

Article::find([
    [
        'article_slug' => 'test-article-title'
    ]
]);

Because we will be using MongoDB later, for now, we will just set up the connection...