ThinkPHP版本 3.2.3
错误信息
[2] Illegal string offset 'id' E:\wamp\www\TPBlog\ThinkPHP\Library\Think\Model\RelationModel.class.php 第 340 行.
Admin\Model\BlogRelationModel.class.php;
Class BlogRelationModel extends RelationModel{
protected $tableName = 'blog';
protected $_link = array(
'attr' => array(
'mapping_type' => self::MANY_TO_MANY,
'mapping_name' => 'attr',
'class_name' => 'attr',
'foreign_key' => 'bid',
'relation_foreign_key' => 'aid',
'relation_table' => 'hd_blog_attr'
)
);
}
Admin\Controller\BlogController.class.php; public function addBlogHandle(){
$data = array(
'title' => $_POST['title'],
'content' => $_POST['content'],
'time' => time(),
'click' => (int) $_POST['click'],
'cid' => (int) $_POST['cid']
);
if (isset($_POST['aid'])) {
foreach ($_POST['aid'] as $v) {
$data['attr'][] = $v;
}
}
D('BlogRelation')->relation(true)->add($data);
$this->display();
}
Think\Model\RelationModel.class.php; case self::MANY_TO_MANY:
$mappingRelationFk = $val['relation_foreign_key']?$val['relation_foreign_key']:$model->getModelName().'_id';// 关联
$prefix = $this->tablePrefix;
if(isset($val['relation_table'])){
$mappingRelationTable = preg_replace_callback("/__([A-Z_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $val['relation_table']);
}else{
$mappingRelationTable = $this->getRelationTableName($model);
}
if(is_array($mappingData)) {
$ids = array();
foreach ($mappingData as $vo)
$ids[] = $vo[$mappingKey]; //第340行
$relationId = implode(',',$ids);
}
最佳答案
