YII中的setAttribute()函数不起作用
我将PHP Yii框架与MongoDB(YiMongoDBSuite)一起使用。我创建了一个从EMongoDocument扩展而来的模型YII中的setAttribute()函数不起作用,yii,Yii,我将PHP Yii框架与MongoDB(YiMongoDBSuite)一起使用。我创建了一个从EMongoDocument扩展而来的模型 <?php class MyModel extends EMongoDocument { public $attr1; public $attr2; // rules, custom validations and other functions.... public function setAttrib
<?php
class MyModel extends EMongoDocument
{
public $attr1;
public $attr2;
// rules, custom validations and other functions....
public function setAttributes($values, $safeOnly=true)
{
if(!is_array($values))
return;
if($this->hasEmbeddedDocuments())
{
$attributes=array_flip($safeOnly ? $this->getSafeAttributeNames() : $this->attributeNames());
foreach($this->embeddedDocuments() as $fieldName => $className)
if(isset($values[$fieldName]) && isset($attributes[$fieldName]))
{
$this->$fieldName->setAttributes($values[$fieldName], $safeOnly);
unset($values[$fieldName]);
}
}
parent::setAttributes($values, $safeOnly);
}
}
上述代码未设置属性值。
如果有什么错误,请告诉我 您需要确保在每个级别上使用“安全”验证规则
要了解更多信息,请阅读此尝试确定您有哪些价值错误:
if(!$model->validate()) {
die( print_r($model->getErrors()) );
}
你有安全列表中的属性吗?如果调试代码时,未能设置->属性?@Pentium10,则属性不仅是字符串,而且也是数组格式。。。是的,它无法设置属性,但在调用save()方法时没有给出任何错误。但数据未保存在数据库中。在调用“保存”之前,您需要进行调试,并查看属性中是否有值。@Pentium10已选中,属性中没有值。然后对其进行调试,在其中放置大量echo/print\r,并查看失败的位置。这是一个可以在论坛上解决的问题。
if(!$model->validate()) {
die( print_r($model->getErrors()) );
}