本文整理汇总了PHP中yii\db\ActiveRecord::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::setAttributes方法的具体用法?PHP ActiveRecord::setAttributes怎么用?PHP ActiveRecord::setAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::setAttributes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* @inheritdoc
*/
public function init()
{
if (!$this->modelClass) {
throw new InvalidArgumentException('Param "modelClass" must be non-empty');
}
if (!is_subclass_of($this->modelClass, 'voskobovich\\base\\interfaces\\ModelInterface')) {
throw new InvalidArgumentException('Param "modelClass" must be extend "voskobovich\\base\\interfaces\\ModelInterface"');
}
$this->_model = Yii::createObject($this->modelClass);
$this->_model->setAttributes($this->initAttributes);
parent::init();
}
示例2: setAttributes
/**
* rewrite set attributes, set relation data to relations, auto save at after save
* @inheritdoc
*/
public function setAttributes($values, $safeOnly = true)
{
if (is_array($values)) {
foreach ($values as $name => $value) {
$this->tryToSetRelation($name, $value);
}
}
parent::setAttributes($values, $safeOnly);
}
示例3: setAttributes
public function setAttributes($values, $safeOnly = true)
{
if (is_array($values)) {
foreach ($values as $key => $value) {
if (is_array($value)) {
unset($values[$key]);
}
}
}
parent::setAttributes($values, $safeOnly);
}
示例4: setAttributes
/**
* Extends setAttributes to handle active date fields
*
* @param $values array
* @param $safeOnly boolean
*/
public function setAttributes($values, $safeOnly = true)
{
foreach ($this->widgetAttributes() as $fieldName => $className) {
$className = '\\marsoltys\\yii2user\\components\\' . $className;
if (isset($values[$fieldName]) && class_exists($className)) {
$class = new $className();
$arr = $this->widgetParams($fieldName);
if ($arr) {
$newParams = $class->params;
$arr = (array) Json::decode($arr);
foreach ($arr as $p => $v) {
if (isset($newParams[$p])) {
$newParams[$p] = $v;
}
}
$class->params = $newParams;
}
if (method_exists($class, 'setAttributes')) {
$values[$fieldName] = $class->setAttributes($values[$fieldName], $this, $fieldName);
}
}
}
parent::setAttributes($values, $safeOnly);
}
示例5: setAttributes
public function setAttributes($attributes)
{
$model = $this->getModel();
foreach ($attributes as $attribute => $value) {
if (in_array($attribute, $this->pageAttributes)) {
$model->title = $value;
unset($attributes[$attribute]);
continue;
}
}
$model->save();
$attributes['pageId'] = $model->id;
parent::setAttributes($attributes);
}
示例6: setAttributes
/**
* Check if some attributes uploaded via fileInput field
* and assign them with UploadedFile
*
* @inheritdoc
*/
public function setAttributes($values, $safeOnly = true)
{
parent::setAttributes($values, $safeOnly);
// Looking only for file attributes (and fix null error on fly)
if (is_array($values)) {
$attributes = array_flip($safeOnly ? $this->safeAttributes() : $this->attributes());
$class = StringHelper::basename(get_called_class());
foreach ($values as $name => $value) {
if (isset($attributes[$name])) {
if (isset($_FILES[$class]['name'][$name])) {
$uploadedFile = UploadedFile::getInstance($this, $name);
if ($uploadedFile) {
$this->{$name} = $uploadedFile;
} elseif (!$this->isNewRecord) {
$this->{$name} = $this->oldAttributes[$name];
}
}
}
}
}
}
示例7: _setValue
/**
* @inheritDoc
*/
protected function _setValue(ActiveRecord $model, $value)
{
/** @var ActiveRecord $model */
$model->setAttributes([$this->attributeName => $value]);
return true;
}
示例8: setAttributes
/**
* (non-PHPdoc)
* @see \yii\base\Model::setAttributes()
* @throws Exception if the current record is read only
*/
public function setAttributes($values, $safeOnly = true)
{
if ($this->getReadOnly()) {
throw new Exception('Attempting to set attributes on a read only ' . Tools::getClassName($this) . ' model');
}
parent::setAttributes($values, $safeOnly);
}