문제

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