Models

    1. Provide an abstraction layer to the underlying data source(s)
    2. Help with validating data.

    Also, li3 makes it easy to extend models so that they fit your application’s needs. Thanks to the nifty autoloading mechanism, models are lazy-loaded and are only initialized when you need them. In the next sections you will learn how to use models and perform common operations on them. Later sections will provide you with a more detailed look on models like between them and how to extend models to fit your application’s needs.


    As the framework is capable of working with document oriented data sources as it is with relational databases, we use the term entity to refer to what might be considered a document in one data source type or a record/row in another type.

    Models allow you to interact with your data in two fundamentally different ways: and data mutation (saving/updating/deleting). All query-related operations may be done through the static find() method, along with some additional utility methods provided for convenience. Classes extending the Model class should, conventionally, be named as plural, CamelCase and be placed in the directory. i.e. a posts model would be model/Posts.php.

    Creating a Model

    li3 provides you with a general-purpose class that all your models should extend. You can find the Model class in the namespace. If you do nothing more than extend it, you instantly get a bunch of functionality that covers basic CRUD as well as more complex tasks.


    li3 also allows model creation via the console: You can enter into the command line (assuming you have configured the command line for use) and the code above will automatically be created in a file called \app\models\Posts.php.