1. Modify the APP/config/database. php file and configure both databases first. The configuration content of MySQL and PostgreSQL is also mounted below.
Class database_config {
VaR $ default = array (
'Driver '=> 'mysql ',
'Persistent' => false,
'Host' => 'localhost ',
'Login' => 'eschool _ user ',
'Password' => 'Password ',
'Database' => 'eschool ',
'Prefix' => '',
);
VaR $ common = array (
'Driver '=> 'codecs ',
'Persistent' => false,
'Host' => 'localhost ',
'Login' => 'logs ',
'Password' => 'Password ',
'Database' => 'new _ TSA ',
'Prefix' => '',
);
}
2. Start to write the model file of your database. below is one of them.
<? PHP
Class pggrade extends appmodel {
VaR $ name = 'pggrade ';
// This statement indicates that the common database configuration is used.
VaR $ usedbconfig = 'common ';
// Custom table name
VaR $ usetable = 'grade ';
// Customize the table's primary key
VaR $ primarykey = 'grade _ id ';
// Field constraints
VaR $ validate = array (
'Grade _ name' => array ('notempty '),
);
// Link settings
VaR $ hasmany = array (
'Pguserinfo' => array (
'Classname' => 'pguserinfo ',
'Foreignkey' => 'grade _ id ',
'Dependent' => true,
'Condition' => '',
'Fields' => '',
'Order' => '',
'Limit' => '',
'Offset' => '',
'Clusive '=> '',
'Finderquery' => '',
'Counterquery' =>''
)
);
}
?>
3. The configuration has been completed. You can test and use it in CRL, as shown in figure
Class libcontroller extends appcontroller {
VaR $ name = 'lib ';
VaR $ helpers = array ('html', 'form ');
VaR $ layout = 'show ';
VaR $ uses = array ('pggrade ');
//////////////////////////////////////// //////////////////////////////////////// /////////////////
Function Index ($ tea_id = NULL)
{
Pr ($ this-> pggrade> Find ('all '));
Exit;
}
}
# PHP Column