本文整理汇总了PHP中common\models\Article::multiSave方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::multiSave方法的具体用法?PHP Article::multiSave怎么用?PHP Article::multiSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Article
的用法示例。
在下文中一共展示了Article::multiSave方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpdate
/**
* Updates an existing Article model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$firstModel = $this->findModel($id);
foreach (Yii::$app->params['availableLocales'] as $key => $value) {
$currentModel = Article::getLocaleInstance($key);
$dataModel = $currentModel::find()->andWhere(['locale_group_id' => $firstModel->locale_group_id, 'locale' => $key])->one();
$dataModel->categoriesList = $this->getCategoriesListIds($dataModel->id);
if (!empty($dataModel->domain)) {
$dataModel->domain = explode(',', $dataModel->domain);
}
$models[$key] = $dataModel;
if (!$models[$key]) {
$currentModel->attributes = $firstModel->attributes;
$currentModel->attachments = $firstModel->attachments;
$currentModel->thumbnail = $firstModel->thumbnail;
$currentModel->categoriesList = $firstModel->categoriesList;
//$currentModel->video = $firstModel->video;
$currentModel->locale_group_id = $firstModel->locale_group_id;
$currentModel->locale = $key;
$currentModel->title = 'title ' . $key . ' ' . time();
$currentModel->descripton = $firstModel->description;
$currentModel->slug = '';
$models[$key] = $currentModel;
}
}
$model = new MultiModel(['models' => $models]);
if ($model->load(Yii::$app->request->post()) && Article::multiSave($model)) {
return $this->redirect(['index']);
} else {
switch ($firstModel->on_scenario) {
case 'extend':
$viewName = 'extend';
break;
default:
$viewName = 'update';
}
return $this->render($viewName, ['model' => $model, 'categories' => ArticleCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
}
}
示例2: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
foreach (Yii::$app->params['availableLocales'] as $key => $value) {
$currentModel = Article::getLocaleInstance($key);
$currentModel->locale = $key;
//$currentModel->title = 'title ' . $key . ' ' . time();
$models[$key] = $currentModel;
}
$model = new MultiModel(['models' => $models]);
if ($model->load(Yii::$app->request->post()) && Article::multiSave($model)) {
return $this->redirect(['index']);
} else {
//print_r(array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls'))));
//die()
return $this->render('create', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
}
}