My app requires me to use 2 databases. Most models use data from only one model but some models require me to use a different database. Is it possible to specify in a model which database to use? I am using MongoDB for my database.

有帮助吗?

解决方案

The Lithium docs explain multiple connections, in the section "Model Creation and Configuration"

From that page, if you want to use the "backup" connection:

<?php
namespace app\models;
class Posts extends \lithium\data\Model {
    protected $_meta = array(
        'connection' => 'backup'
    );
}
?>

Further explanation from the same page:

Once your model's $_meta property has been configured, Lithium merges it with the default settings at runtime. Because the Post model has a specified connection, the backup connection is used instead of the default.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top