本文整理汇总了PHP中yii\db\ActiveRecord::load方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::load方法的具体用法?PHP ActiveRecord::load怎么用?PHP ActiveRecord::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public function load($data)
{
if (isset($data[self::getAdditionForm()])) {
$this->additionFieldsForm = $data[self::getAdditionForm()];
}
return parent::load($data);
}
示例2: load
/**
* @param array $data
* @param null $formName
* @return bool
*/
public function load($data, $formName = null)
{
$this->trigger(self::EVENT_BEFORE_LOAD);
$result = parent::load($data, $formName);
$this->trigger(self::EVENT_AFTER_LOAD);
return $result;
}
示例3: load
public function load($data, $formName = null)
{
foreach ($data as $name => $value) {
$this->tryToSetRelation($name, $value);
}
return parent::load($data, $formName);
}
示例4: load
/**
* @inheritdoc
*/
public function load($data, $formName = null)
{
$data = GxModelHelper::adaptToMassiveAssignment($data, static::className());
if (false === $formName) {
$formName = '';
}
return parent::load($data, $formName);
}
示例5: load
public function load($data, $formName = null)
{
if ($this->widgetModel !== null) {
$this->widgetModel->load($data, $formName);
return parent::load($data, $formName);
} else {
return parent::load($data, $formName);
}
}
示例6: load
public function load($data, $formName = null)
{
if (parent::load($data, $formName)) {
if ($this->scenario == self::SCENARIO_FILE_UPLOAD) {
if (!$this->fileUpload instanceof UploadedFile) {
$this->fileUpload = UploadedFile::getInstance($this, 'fileUpload');
}
}
return true;
} else {
return false;
}
}
示例7: load
/**
* inherite load() function
*/
public function load($data, $formName = null)
{
parent::load($data, $formName);
if ($this->attributes['time_point']) {
$dateTime = \DateTime::createFromFormat("Y-m-d?H:i:s?", $this->attributes['time_point']);
$this->setAttributes(['time_point' => $dateTime->format('Y-m-d H:i:s')]);
}
if (null == $this->attributes['primary_pollutant']) {
$this->setAttributes(['primary_pollutant' => '']);
}
if (null == $this->attributes['quality']) {
$this->setAttributes(['quality' => '']);
}
}
示例8: loadWithTranslations
/**
* Load owner model and translation models from data.
* @param $data
* @param null $languages array of languages for loading
* @param null $formName
* @param null $translationFormName
* @return bool
*/
public function loadWithTranslations($data, $languages, $formName = null, $translationFormName = null)
{
if ($this->owner->load($data, $formName)) {
if (!$languages) {
throw new InvalidParamException('Languages must be set.');
}
foreach ($languages as $language) {
$modelI18n = static::getTranslation($language);
$modelI18n->load($data, $translationFormName);
}
return true;
}
return false;
}
示例9: load
public function load($data, $formName = null)
{
$loaded = parent::load($data, $formName);
if (!$this->date) {
$this->date = date('Y-m-d H:i:s');
} else {
$this->date = date('Y-m-d H:i:s', strtotime($this->date));
}
$scope = $formName === null ? $this->formName() : $formName;
if (isset($data[$scope])) {
if (isset($data[$scope]['outgoing'])) {
foreach ($data[$scope]['outgoing'] as $key => $outgoing) {
if (isset($this->outgoings[$key])) {
$loaded &= $this->outgoings[$key]->load($outgoing, '');
} else {
$out = new TransactionOutgoing();
$out->id = $key;
$loaded &= $out->load($outgoing, '');
$this->outgoings[] = $out;
}
}
}
if (isset($data[$scope]['incoming'])) {
foreach ($data[$scope]['incoming'] as $key => $incoming) {
if (isset($this->incomings[$key])) {
$loaded &= $this->incomings[$key]->load($incoming, '');
} else {
$in = new TransactionIncoming();
$in->id = $key;
$loaded &= $in->load($incoming, '');
$this->incomings[] = $in;
}
}
}
if (isset($data[$scope]['expense'])) {
foreach ($data[$scope]['expense'] as $key => $expense) {
if (isset($this->expenses[$key])) {
$loaded &= $this->expenses[$key]->load($expense, '');
} else {
$exp = new TransactionExpense();
$exp->id = $key;
$loaded &= $exp->load($expense, '');
$this->expenses[] = $exp;
}
}
}
}
return $loaded;
}
示例10: searchQuery
/**
* @param ActiveRecord $model
* @param array $opts
* @return ActiveQuery | array
*/
static function searchQuery($model, $opts = [])
{
$opts = ArrayHelper::merge(['data' => null, 'query' => null, 'columns' => [], 'filters' => []], $opts);
$columns = $opts['columns'];
$filters = $opts['filters'];
$data = $opts['data'];
if (null === $data) {
$data = \Yii::$app->request->get();
}
$query = $opts['query'];
if (is_string($query)) {
$query = call_user_func([$model, $opts['query']]);
} elseif (null === $query) {
$query = $model->find();
foreach (array_filter($model->getAttributes()) as $prop => $val) {
$query->andWhere([$prop => $val]);
}
}
if ($model->load($data) && $model->validate()) {
foreach ($model->getAttributes($model->safeAttributes()) as $name => $value) {
if ($model->isAttributeChanged($name)) {
$attributeTypes = [];
if (method_exists($model, 'attributeTypes')) {
$attributeTypes = $model->attributeTypes();
}
$type = null;
if (isset($attributeTypes[$name])) {
$type = $attributeTypes[$name];
}
// Default filter function
$filterFunc = isset($filters[$name]) && is_callable($filters[$name]) ? $filters[$name] : function (ActiveQuery $query, $name, $value, $type) {
/**
* @var string $name
* @var string|array $value
* @var string $type
*/
$query->andFilterWhere(static::searchAttribute($name, $value, $type));
};
if (isset($columns[$name])) {
$name = $columns[$name];
}
call_user_func($filterFunc, $query, $name, $value, $type);
}
}
}
return $query;
}
示例11: load
public function load($data, $formName = null)
{
if (parent::load($data, $formName)) {
$scope = $formName === null ? $this->formName() : $formName;
if ($scope) {
$data = $data[$scope];
}
$extraFields = $this->parseExtraField();
foreach ($data as $attr => $value) {
if (in_array($attr, $extraFields)) {
$this->{$attr} = $value;
}
}
return true;
} else {
return false;
}
}
示例12: load
public function load($data, $formName = null)
{
parent::load($data, $formName);
if (!(Yii::$app->user->id > 0)) {
$this->addError('seller_id');
return;
}
//print_r($this); die();
//print_r($data); die();
//$this->id = $data['id'];
$this->title = $data['title'];
$this->description = $data['description'];
$this->img_url = $data['img_url'];
$this->price = (int) $data['price'];
$this->seller_id = Yii::$app->user->id;
$this->trash = 0;
$this->categoriesArr = explode('_', $data['selected_categories']);
foreach ($this->categoriesArr as $k => $v) {
if (!((int) $v > 0)) {
unset($this->categoriesArr[$k]);
}
}
}
示例13: saveSettingsModel
/**
* Save model of settings
* @param ActiveRecord $model Model to save
* @param array $requestParams Request parameters
* @return bool
*/
protected function saveSettingsModel(ActiveRecord $model, array $requestParams)
{
$success = false;
$transaction = $model->getDb()->beginTransaction();
try {
$model->load($requestParams);
if ($model->save()) {
$transaction->commit();
Yii::$app->interfaceSettings->refreshUserInterfaceSettings($model->user_id, $model->interface_id);
$success = true;
} else {
throw new Exception();
}
} catch (Exception $e) {
if ($transaction->isActive) {
$transaction->rollBack();
}
}
// trigger an event
$this->trigger(self::EVENT_SAVE_SETTING, new ExtraDataEvent(['extraData' => ['model' => $model, 'success' => $success]]));
return $success;
}
示例14: load
public function load($data, $formName = null)
{
if ($res = parent::load($data, $formName)) {
$this->htmlAttributes = $data['htmlAttributes'];
}
}
示例15: load
/**
* @inheritdoc
*/
public function load($data, $formName = null)
{
return parent::load($data, $formName) && $this->loadValues($data);
}