Exemplo n.º 1
0
 /**
  *新增和修改提交
  * @return array
  */
 public function actionSubmit()
 {
     $params = Yii::$app->request->post();
     if (isset($params["community_id"])) {
         $model = $this->findModel($params["community_id"]);
     } else {
         $model = new Community();
         $params["create_at"] = date("Y-m-d");
         $params["user_id"] = Yii::$app->user->getId();
     }
     $data = array();
     //yii自动生成的form参数是Enterprise["name"]这种形式,获取后就会是在一个Enterprise中
     $data["Community"] = $params;
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if ($model->load($data) && $model->save()) {
         return ["success" => true];
     } else {
         return ["success" => false, "error_code" => 1];
     }
 }
Exemplo n.º 2
0
 /**
  * Method to save community
  *
  * @param array $val
  * @param \App\Models\Community $community
  * @return boolean
  */
 public function save($val, $community)
 {
     $expected = ['description' => '', 'title' => '', 'can_post' => '', 'searchable' => '', 'info' => []];
     /**
      * @var $description
      * @var $title
      * @var $can_post
      * @var $searchable
      * @var $info
      */
     extract(array_merge($expected, $val));
     $community->description = \Hook::fire('filter-text', sanitizeText($description));
     $community->can_post = sanitizeText($can_post);
     $community->searchable = sanitizeText($searchable);
     $community->info = perfectSerialize($info);
     $community->title = sanitizeText($title);
     $community->save();
     return true;
 }