What is a model?
Models are PHP classes designed to be the primary way of interacting with Nova’s database. Each model has its own set of methods for different things it can pull out of the database, so if you’re working with a model, it’s important to look at what methods that model provides.You can read more about CodeIgniter’s models in their documentation.
autoload.php
config file). In some rare instances, Nova will pre-load models in the controller’s constructor simply to reduce the amount of boilerplate code that needs to be written, but in most cases, models aren’t loaded ahead of time. This means that before interacting with a model, you will need to load it:
All of Nova’s available models can be found in the
nova/modules/core/models
directory.Extending models
In order to provide as much flexibility as possible, Nova is split up into two distinct layers: the core and the application. Any work Anodyne does on Nova lives inside “the core”. Any work that you do on your game’s site is “the application”. This is done to ensure that any update to Nova doesn’t reset the changes you’ve made to your installation of Nova.Core models
The “core” layer of Nova is considered anything that lives inside thenova
directory. (As an aside, this is what allows for the simplicity of only needing to replace the nova
directory when updating to the latest version.)
When it comes to models, you’ll find that all of Nova’s core models are located in the nova/modules/core/models
directory. To avoid naming conflicts, all of Nova’s core models are prefixed with nova_
.
Application models
The “application” layer of Nova is considered anything that lives outside of thenova
directory.
When it comes to models, all of Nova’s application models are located in the application/models
directory. Nova comes with all of the needed models out of the box, but if you want to create new models for interacting with new database tables you’ve created, you can add your own models here.
Customizations
When you open an application model, you’ll see a file that looks something like this:application/models/Characters_model.php
When it comes to overriding a model method, the recommended way of doing that is to copy the method from the core model and paste it into the application model. You then have a working copy of the method from which to modify whatever you want.