Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ORM的Kohana数据库配置设置_Php_Kohana - Fatal编程技术网

Php ORM的Kohana数据库配置设置

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

如何选择我的ORM应该使用的数据库配置?文档只提到了如何设置配置并在使用纯数据库方法时选择它。在使用ORM时不会

这是我当前的配置:

控制器

<?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';
}