/** * Updates an existing Service model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); //$model->getSectionsId(); $secServiceList = SecService::find()->select(['id', 'header'])->all(); $secServiceList = ArrayHelper::map($secServiceList, 'id', 'header'); // или // $secServiceList = SecService::find()->select(['header', 'id'])->indexBy('id')->column(); if ($model->load(Yii::$app->request->post())) { $transaction = Service::getDb()->beginTransaction(); if ($model->save()) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } else { $transaction->rollBack(); return $this->render('update', ['model' => $model, 'secServiceList' => $secServiceList]); } } else { return $this->render('update', ['model' => $model, 'secServiceList' => $secServiceList]); } }
/** * 查询发布的咨询,缓存1分钟 * @param null $limit * @return array|\yii\db\ActiveRecord[] */ public static function findPublished($limit = null) { if ($limit) { return Service::getDb()->cache(function () use($limit) { return Service::find()->where(['state' => Service::STATE_PUBLISH])->limit($limit)->orderBy(['replyDate' => SORT_DESC])->all(); }, 60); } else { return Service::getDb()->cache(function () { return Service::find()->where(['state' => Service::STATE_PUBLISH])->orderBy(['replyDate' => SORT_DESC])->all(); }, 60); } }