Kohana ORM:数组到字符串转换错误

时间:2011-12-01 16:50:50

标签: php orm kohana

我尝试在我的localhost xampp上使用Kohana / ORM,我收到以下错误

ErrorException [注意]:数组转换为字符串 MODPATH \ orm \ classes \ kohana \ orm.php [980]

975             }
976             else
977             {
978                 // List columns and mirror for performance
979                 $this->_table_columns = $this->list_columns();
980                 $this->_table_columns = array_combine($this->_table_columns, $this->_table_columns);
981 
982                 // Load column cache
983                 ORM::$_column_cache[$this->_object_name] = $this->_table_columns;
984             }
985         }

这似乎是出现在不同的Frameworks / PHP应用程序中的常见错误,但我没有找到任何修复它的线索。

模型只是基本的ORM

class Model_Product extends ORM {

}

Mysql表(InnoDB - UTF-8)有两个字段 id - primary int name - varchar 50

在任何地方都没有伏都教,非常感谢帮助

提前感谢!

编辑:请求的vardump

array(2) {
  ["id"]=>
  array(13) {
    ["type"]=>
    string(3) "int"
    ["min"]=>
    string(11) "-2147483648"
    ["max"]=>
    string(10) "2147483647"
    ["column_name"]=>
    string(2) "id"
    ["column_default"]=>
    NULL
    ["data_type"]=>
    string(3) "int"
    ["is_nullable"]=>
    bool(false)
    ["ordinal_position"]=>
    int(1)
    ["display"]=>
    string(2) "11"
    ["comment"]=>
    string(0) ""
    ["extra"]=>
    string(14) "auto_increment"
    ["key"]=>
    string(3) "PRI"
    ["privileges"]=>
    string(31) "select,insert,update,references"
  }
  ["name"]=>
  array(12) {
    ["type"]=>
    string(6) "string"
    ["column_name"]=>
    string(4) "name"
    ["column_default"]=>
    NULL
    ["data_type"]=>
    string(7) "varchar"
    ["is_nullable"]=>
    bool(false)
    ["ordinal_position"]=>
    int(2)
    ["character_maximum_length"]=>
    string(2) "50"
    ["collation_name"]=>
    string(15) "utf8_general_ci"
    ["comment"]=>
    string(0) ""
    ["extra"]=>
    string(0) ""
    ["key"]=>
    string(0) ""
    ["privileges"]=>
    string(31) "select,insert,update,references"
  }
}

2 个答案:

答案 0 :(得分:1)

第980行:

980                 $this->_table_columns = array_combine($this->_table_columns, $this->_table_columns);
考虑到前一行979,

看起来多余:

979                 $this->_table_columns = $this->list_columns();

合并两次相同的数组是没用的,特别是当数组是这样的时候:

array(2) {
  ["id"]=>
  array(13) {
    ["type"]=>
    string(3) "int"
    ["min"]=>
    string(11) "-2147483648"
    ["max"]=>
    string(10) "2147483647"
    ["column_name"]=>
    string(2) "id"
    ["column_default"]=>
    NULL
    ["data_type"]=>
    string(3) "int"
    ["is_nullable"]=>
    bool(false)
    ["ordinal_position"]=>
    int(1)
    ["display"]=>
    string(2) "11"
    ["comment"]=>
    string(0) ""
    ["extra"]=>
    string(14) "auto_increment"
    ["key"]=>
    string(3) "PRI"
    ["privileges"]=>
    string(31) "select,insert,update,references"
  }
  ["name"]=>
  array(12) {
    ["type"]=>
    string(6) "string"
    ["column_name"]=>
    string(4) "name"
    ["column_default"]=>
    NULL
    ["data_type"]=>
    string(7) "varchar"
    ["is_nullable"]=>
    bool(false)
    ["ordinal_position"]=>
    int(2)
    ["character_maximum_length"]=>
    string(2) "50"
    ["collation_name"]=>
    string(15) "utf8_general_ci"
    ["comment"]=>
    string(0) ""
    ["extra"]=>
    string(0) ""
    ["key"]=>
    string(0) ""
    ["privileges"]=>
    string(31) "select,insert,update,references"
  }
}

它只包含字符串键。您应该使用kohana框架打开错误报告。

评论第980行,直到此修复为止。

答案 1 :(得分:0)

我找到了解决此错误的方法,只需在模型中声明表格列。

protected $_table_columns = array(
    'column' => NULL,
    'names'  => NULL,
    'go'     => NULL,
    'here'   => NULL,
    ......
);

这将解决问题并提高性能。