Php ORM的Kohana数据库配置设置
如何选择我的ORM应该使用的数据库配置?文档只提到了如何设置配置并在使用纯数据库方法时选择它。在使用ORM时不会 这是我当前的配置: 控制器Php ORM的Kohana数据库配置设置,php,kohana,Php,Kohana,如何选择我的ORM应该使用的数据库配置?文档只提到了如何设置配置并在使用纯数据库方法时选择它。在使用ORM时不会 这是我当前的配置: 控制器 <?php defined('SYSPATH') or die('No direct script access.'); class Controller_Welcome extends Controller { public function action_index() { $members = ORM::fa
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Welcome extends Controller {
public function action_index()
{
$members = ORM::factory('user');
$members->where('first_name', '=', 'Peter')->find_all();
$memCount = $members->count_all();
$this->response->body('Count: ' . $memCount);
}
} // End Welcome
您可能知道,Kohana默认使用default
。如果您希望在默认情况下有所不同,请将此行添加到bootstrap.php
:
Database::$default = "local";
这应该可以做到这一点。就像Kowser所说的,对于Database::instance(),要使用“local”数据库组返回连接,请使用Database::$default='local'
如果要让类使用非数据库的特定数据库组::$default。
然后在类定义中将$\u db\u group设置为数据库配置组,如下所示:
<?php defined('SYSPATH') or die('No direct access allowed.');
class Model_User extends ORM
{
protected $_db_group = 'local';
protected $_primary_key = 'UserId';
}
别忘了为其他型号设置默认值
DB设置。您可以使用类似于$config['default']=$config['local'];返回$config代码>在配置中。
Database::$default = "local";
<?php defined('SYSPATH') or die('No direct access allowed.');
class Model_User extends ORM
{
protected $_db_group = 'local';
protected $_primary_key = 'UserId';
}