{"action":"opened","issue":{"url":"https://api.github.com/repos/top-think/think/issues/588","repository_url":"https://api.github.com/repos/top-think/think","labels_url":"https://api.github.com/repos/top-think/think/issues/588/labels{/name}","comments_url":"https://api.github.com/repos/top-think/think/issues/588/comments","events_url":"https://api.github.com/repos/top-think/think/issues/588/events","html_url":"https://github.com/top-think/think/issues/588","id":195756874,"number":588,"title":"model怎么正确从配置文件中读取配置并生效？","user":{"login":"TIGERB","id":12149373,"avatar_url":"https://avatars.githubusercontent.com/u/12149373?v=3","gravatar_id":"","url":"https://api.github.com/users/TIGERB","html_url":"https://github.com/TIGERB","followers_url":"https://api.github.com/users/TIGERB/followers","following_url":"https://api.github.com/users/TIGERB/following{/other_user}","gists_url":"https://api.github.com/users/TIGERB/gists{/gist_id}","starred_url":"https://api.github.com/users/TIGERB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TIGERB/subscriptions","organizations_url":"https://api.github.com/users/TIGERB/orgs","repos_url":"https://api.github.com/users/TIGERB/repos","events_url":"https://api.github.com/users/TIGERB/events{/privacy}","received_events_url":"https://api.github.com/users/TIGERB/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-15T09:33:40Z","updated_at":"2016-12-15T09:33:40Z","closed_at":null,"body":"我看了下think/model的代码，如果不设置需要自动写入时间戳为真，实例化的时候就会执行$this->db()建立一次连接（生成缓存）\r\n\r\n```\r\n  /**\r\n     * 架构函数\r\n     * @access public\r\n     * @param array|object $data 数据\r\n     */\r\n    public function __construct($data = [])\r\n    {\r\n      ...\r\n        if (is_null($this->autoWriteTimestamp)) {\r\n            // 自动写入时间戳\r\n            $this->autoWriteTimestamp = $this->db()->getConfig('auto_timestamp');\r\n        }\r\n      ...\r\n    }\r\n```\r\n\r\n当我复写了$connection配置，执行到$this->db()返回的还是上次缓存的连接, 并没有reset掉连接配置,下面的代码\r\n\r\n```\r\n/**\r\n     * 获取当前模型的数据库查询对象\r\n     * @access public\r\n     * @param bool $baseQuery 是否调用全局查询范围\r\n     * @return Query\r\n     */\r\n    public function db($baseQuery = true)\r\n    {\r\n        $model = $this->class;\r\n        if (!isset(self::$links[$model])) {\r\n            ...\r\n        }\r\n        // 返回当前模型的数据库查询对象\r\n        return self::$links[$model];\r\n    }\r\n```\r\n所以，现在我怎样才能让model使用从配置文件中读取的配置？"}}
{"actor":{"display_login":"TIGERB"}}