本文整理汇总了PHP中yii\base\DynamicModel::getAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP DynamicModel::getAttributes方法的具体用法?PHP DynamicModel::getAttributes怎么用?PHP DynamicModel::getAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\DynamicModel
的用法示例。
在下文中一共展示了DynamicModel::getAttributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionBook
public function actionBook($id)
{
$model = new Booking();
$bookingModelAttributes = ['group_num', 'agency_id'];
$customFieldsAttributes = array_map(function ($item) {
return 'field' . $item['id'];
}, $this->findModel($id)->getFields()->all());
$dynamicModelAttributes = array_merge($bookingModelAttributes, $customFieldsAttributes);
$dynamicModel = new DynamicModel($dynamicModelAttributes);
$dynamicModel->addRule($dynamicModelAttributes, 'required');
if ($dynamicModel->load(Yii::$app->request->post()) && $dynamicModel->validate()) {
$attributes = $dynamicModel->getAttributes($bookingModelAttributes);
$model->link('tour', $this->findModel($id));
$model->agency_id = $attributes['agency_id'];
$model->group_num = $attributes['group_num'];
$model->time = time();
if ($model->validate()) {
$fields = [];
$keys = ['booking_id', 'tour_id', 'field_id', 'value'];
foreach ($dynamicModel->getAttributes($customFieldsAttributes) as $key => $field) {
if (in_array($key, $customFieldsAttributes)) {
$fields[] = [$model->id, $id, str_replace('field', '', $key), $field];
}
}
if (!empty($fields)) {
Yii::$app->db->createCommand()->batchInsert('booking_fields', $keys, $fields)->execute();
$model->save();
return $this->redirect('/booking');
}
} else {
var_dump($model);
$model->delete();
}
}
return $this->render('book', ['model' => $dynamicModel, 'tourModel' => $this->findModel($id)]);
}