The Solar_Sql_Model_Catalog class tracks a list of models accessible to your application. The catalog knows how to locate model classes and create instances of them.
The Catalog is often the starting point for any domain operation. You'll want to have easy access to it throughout your application.
For easy use of your catalog You'll want to place it in the Solar Registry for global access. The easiest way to do this is with a registry_set config option in your Solar.config.php file.
$config['Solar']['registry_set']['model_catalog'] = 'Solar_Sql_Model_Catalog';
You may also want to make you're sql object available in the same way.
$config['Solar']['registry_set']['sql'] = 'Solar_Sql';
This will setup your models and sql object to be lazily loaded when accessed from the registry. Doing it this way means that its always available and you never have to check for its existence. Don't forget to configure your sql object.
In your controllers it can be handy to make your catalog available as a local variable. Define the variable.
/** * Tracks available models * @var Solar_Sql_Model_Catalog */ protected $_model;
Then set the value in your Controller's _setup method.
protected function _setup() { $this->_model = Solar_Registry::get('model_catalog'); }
Now your catalog and all its models are at your finger tips.
By default, the catalog will look for model classes in the Solar/Model directory. It might look as some other crazy places based on the class stack. Good luck with that.
Most likely, you will want to keep your models in a single directory, under your Vendor directory (see First Vendor). The easiest way to do that is to set the classes configuration option in your Solar.config.php file.
$config['Solar_Sql_Model_Catalog']['classes'] = array('Vendor_Model');
If you are not using models from Solar_Model, manually specifying the classes option will prevent Solar from looking in places for models where they will not be for your application.
You can use the catalog to access models by their model name.
$all = $this->_model->my_objects->fetchAll();
By default, the catalog will not create an instance of a model class until you ask the catalog to retrieve the class. By using the property access capability of the Catalog, you can avoid unnecessarily creating instances of models that you will not use.