我在 Cake 2.3.5 上使用这个:https ://github.com/ichikaway/cakephp-mongodb
数据库配置
public $mongo = array(
'datasource' => 'Mongodb.MongodbSource',
'database' => 'hello_forms',
'host' => 'localhost',
'port' => 27017,
'persistent' => 'true',
);
该模型:
<?php
class Form extends AppModel {
var $name = 'Form';
var $primaryKey = '_id';
var $useDbConfig = 'mongo';
var $useTable = false;
public $validate = array(
'name' => array(
'rule' => array('notEmpty'),
'message' => 'A list name is required.',
'required' => true
),
);
public function schema() {
$this->_schema = array(
'_id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'length' => 40, 'key' => 'primary'),
// '_id' => array('type' => 'integer', 'key' => 'primary', 'length' => 40),
'name' => array('type' => 'string'),
'unique_string' => array('type' => 'string'),
'account_id' => array('type' => 'integer'),
'description' => array('type' => 'string'),
'success_text' => array('type' => 'string'),
'success_redirect' => array('type' => 'string'),
'created'=>array('type'=>'datetime'),
'modified'=>array('type'=>'datetime'),
'form_elements' => array(
array(
'field_description' => array('type' => 'string'),
'field_label' => array('type' => 'string'),
'field_type' => array('type' => 'string'),
'weight' => array('type' => 'integer'),
'date_format' => array('type' => 'string'),
'is_required' => array('type' => 'boolean'),
'allow_duplicates' => array('type' => 'boolean'),
'meta' => array(
array(
'meta_label' => array('type' => 'string'),
'meta_default_value' => array('type' => 'string'),
'meta_checked' => array('type' => 'boolean')
)
)
),
)
);
return $this->_schema;
}
}
错误:
<b>Notice</b> (8)</a>: Undefined index: length [<b>CORE\Cake\Model\Model.php</b>, line <b>1793</b>]
我一直在努力解决这个问题,但我没有想法。我找到了这个:https ://cakephp.lighthouseapp.com/projects/42648/tickets/3138-undefined-index-length-on-modelsave但我不知道如何“处理”该页面上的信息。
声明架构时我错过了什么吗?我试图为所有字段添加“长度”,但仍然出现该错误。是什么赋予了?
编辑:只是为了澄清,因为它只是 a Notice
,数据仍被保存到 MongoDB 中。但是,它弄乱了我的 JSON 数据。