Before we create a model, we need to make sure the config file knows how to connect to the database. By default, it uses SQLite, but you are more likely to have a MySQL database with tables in it already.
Open the config/Solar.config.php file, and tell Solar_Sql to use the MySQL
adapter:
<?php
// $config['Solar_Sql']['adapter'] = 'Solar_Sql_Adapter_Sqlite';
$config['Solar_Sql']['adapter'] = 'Solar_Sql_Adapter_Mysql';
?>
(There are other adapters as well.)
Next, tell the Solar_Sql_Adapter_Mysql class how to connect:
<?php
// $config['Solar_Sql_Adapter_Sqlite'] = array(
// 'name' => "$system/sqlite/solar.sq3",
// 'mode' => 0775,
// );
$config['Solar_Sql_Adapter_Mysql'] = array(
'host' => 'localhost',
'user' => 'username',
'pass' => 'password',
'name' => 'database',
);
?>
Now we're ready to create model classes from a database table with the
make-model command. Given a table name "foo", you can create the model
classes like this:
$ ./script/solar make-model Example_Model_Foo
You can pass a --table flag to specify a table other than "foo".
You will now find the model files at:
source/
example/
Example/
Model/
Foo.php # the foo table
Foo/
Collection.php # a collection of foo records
Record.php # a single foo record
Locale/
en_US.php # model-specific locale strings
Setup/
index_info.php # indexes on the foo table
table_cols.php # description of foo columns
table_name.php # the table name