-
Notifications
You must be signed in to change notification settings - Fork 2
Using
Create a new modal with the name that you want and set property $useDbConfig to your connection (created on app/config/databases.php). After this, create a property $records as array and set your data.
If your data dont have field ‘id’, change property $primaryKey to your field. You can change the $displayField. You will see some like:
<?php
/* Your comments */
class State extends AppModel {
var $name = 'State';
var $useDbConfig = 'local';
var $displayField = 'name';
var $records = array(
array('id' => 1, 'name' => 'Alabama', 'abbr' => 'AL'),
array('id' => 2, 'name' => 'Alaska', 'abbr' => 'AK'),
array('id' => 3, 'name' => 'Arizona', 'abbr' => 'AZ')
);
}
?>
In your controller you can use $this->State->find(anything);
. You can pass all params that you use in your default database, like ‘conditions’, ‘fields’, ‘order’, ‘limit’, ‘page’, …
No problem, you can! In your model that use MySQL (or other db) you can create associations (belongsTo, hasMany, …) to your local model (using array database). See the sample:
<?php
/**
* Your comments
*
* Supose that you table have born_id as field and this is integer
*/
class User extends AppModel {
var $name = 'User';
var $belongsTo = array(
'Born' => array(
'className' => 'State',
'foregnKey' => 'born_id'
);
);
}
?>
When you use $this->User->find('all');
in you controller, you see that has Born information with data of class State (using ArrayDatasource).