diff --git a/module/common/control.php b/module/common/control.php index a574aeb1d5..05f57ff719 100644 --- a/module/common/control.php +++ b/module/common/control.php @@ -289,7 +289,9 @@ EOT; /** * 设置当前访问的公司信息。 * - * 首先尝试按照当前访问的域名查找对应的公司信息,如果无法查到,再按照默认的域名进行查找。 + * 首先尝试按照当前访问的域名查找对应的公司信息, + * 如果无法查到,再按照默认的域名进行查找。 + * 如果还无法查到,则取第一个公司作为默认的公司。 * 获取公司信息之后,将其写入到$_SESSION中。 * * @access public @@ -305,6 +307,7 @@ EOT; { $company = $this->company->getByDomain(); if(!$company and isset($this->config->default->domain)) $company = $this->company->getByDomain($this->config->default->domain); + if(!$company) $company = $this->company->getFirst(); if(!$company) $this->app->error(sprintf($this->lang->error->companyNotFound, $_SERVER['HTTP_HOST']), __FILE__, __LINE__, $exit = true); $_SESSION['company'] = $company; $this->app->company = $company; diff --git a/module/company/model.php b/module/company/model.php index 7399d3b01d..6a3349f681 100644 --- a/module/company/model.php +++ b/module/company/model.php @@ -36,6 +36,12 @@ class companyModel extends model { return $this->dao->select('*')->from(TABLE_COMPANY)->fetchAll(); } + + /* 获得第一个公司。*/ + public function getFirst() + { + return $this->dao->select('*')->from(TABLE_COMPANY)->orderBy('id')->limit(1)->fetch(); + } /** * 通过域名查找公司信息。