+ -
当前位置:首页 → 问答吧 → 谁能帮我看看这个问题,数据表前缀问题。是否是bug呢?

谁能帮我看看这个问题,数据表前缀问题。是否是bug呢?

时间:2011-06-15

来源:互联网

$model = D('Project');
dump($model);

结果:
["pk:protected"] => string(2) "id"
  ["tablePrefix:protected"] => string(4) "pms_"
  ["tableSuffix:protected"] => string(0) ""
  ["name:protected"] => string(7) "Project"
  ["dbName:protected"] => string(0) ""
  ["tableName:protected"] => string(0) ""
  ["trueTableName:protected"] => string(7) "project"
  ["error:protected"] => string(0) ""
  ["fields:protected"] => array(1) {
    ["_autoinc"] => bool(false)
  }

看了getTableName(),为什么trueTableName还是没有前缀呢?应该是pms_project才对啊。

    /**
     +----------------------------------------------------------
     * 得到完整的数据表名
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     */
    public function getTableName()
    {
        if(empty($this->trueTableName)) {
            $tableName  = !empty($this->tablePrefix) ? $this->tablePrefix : '';
            if(!empty($this->tableName)) {
                $tableName .= $this->tableName;
            }else{
                $tableName .= parse_name($this->name);
            }
            $tableName .= !empty($this->tableSuffix) ? $this->tableSuffix : '';
            if(!empty($this->dbName))
                $tableName    =  $this->dbName.'.'.$tableName;
            $this->trueTableName    =   strtolower($tableName);
        }echo '2'.$this->trueTableName;
        return $this->trueTableName;
    }

作者: vling   发布时间: 2011-06-15

我发现主要是 $this->tablePrefix的值,明明在 __construct 里初始化了,后面值又为空了。
public function getTableName()  这个功能里, $this->tablePrefix 又为空了....

作者: vling   发布时间: 2011-06-15