当前位置: 首页>>代码示例>>PHP>>正文


PHP DynamicModel::load方法代码示例

本文整理汇总了PHP中yii\base\DynamicModel::load方法的典型用法代码示例。如果您正苦于以下问题:PHP DynamicModel::load方法的具体用法?PHP DynamicModel::load怎么用?PHP DynamicModel::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\base\DynamicModel的用法示例。


在下文中一共展示了DynamicModel::load方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionViewAdvert

 public function actionViewAdvert($id)
 {
     $model = Advert::findOne($id);
     $data = ['name', 'email', 'text'];
     $model_feedback = new DynamicModel($data);
     $model_feedback->addRule('name', 'required');
     $model_feedback->addRule('email', 'required');
     $model_feedback->addRule('text', 'required');
     $model_feedback->addRule('email', 'email');
     if (Yii::$app->request->isPost) {
         if ($model_feedback->load(Yii::$app->request->post()) && $model_feedback->validate()) {
             Yii::$app->common->sendMail('Subject Advert', $model_feedback->text);
         }
     }
     $user = $model->user;
     $images = Common::getImageAdvert($model, false);
     $current_user = ['email' => '', 'username' => ''];
     if (!Yii::$app->user->isGuest) {
         $current_user['email'] = Yii::$app->user->identity->email;
         $current_user['username'] = Yii::$app->user->identity->username;
     }
     $coords = str_replace(['(', ')'], '', $model->location);
     $coords = explode(',', $coords);
     $coord = new LatLng(['lat' => $coords[0], 'lng' => $coords[1]]);
     $map = new Map(['center' => $coord, 'zoom' => 15]);
     $marker = new Marker(['position' => $coord, 'title' => Common::getTitleAdvert($model)]);
     $map->addOverlay($marker);
     return $this->render('view_advert', ['model' => $model, 'model_feedback' => $model_feedback, 'user' => $user, 'images' => $images, 'current_user' => $current_user, 'map' => $map]);
 }
开发者ID:vecherskyy,项目名称:dom,代码行数:29,代码来源:MainController.php

示例2: actionStock

 public function actionStock()
 {
     $debug = '';
     $model = new DynamicModel(['vins', 'diller']);
     $model->addRule('vins', 'string')->addRule('diller', 'integer')->addRule(['diller', 'vins'], 'required');
     $list = ArrayHelper::map(Mod\cats\Stock::find()->all(), 'id', 'name');
     $prompt = Yii::t('app', 'Select stock');
     $arrError = [];
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $arrvin = explode("\n", $model->vins);
         foreach ($arrvin as $vin) {
             if ($car = Mod\Car::findOne(['vin' => trim($vin)])) {
                 $status = Mod\CarStatus::findOne(['car_id' => $car->id]);
                 $status->stock_id = $model->diller;
                 $status->save();
             } else {
                 $arrError[] = $vin . ' не найден VIN';
             }
         }
         //			$debug = print_r($arrError, true);
         $debug = implode('<br>', $arrError);
         return $this->render('finish', ['debug' => $debug]);
     }
     $arrVars = ['model' => $model, 'list' => $list, 'prompt' => $prompt, 'selLabel' => 'Склад', 'title' => 'Пакетное перемещение'];
     return $this->render('index', $arrVars);
 }
开发者ID:Ent-ch,项目名称:stock_auto,代码行数:26,代码来源:PaketController.php

示例3: actionVerify

 public function actionVerify()
 {
     $session = Yii::$app->session;
     $urlKey = $this->filter->buildKey('_url');
     $urls = $session->get($urlKey);
     if (is_array($urls) && isset($urls[0], $urls[1])) {
         $route = $urls[0];
         $returnUrl = $urls[1];
     } else {
         throw new \yii\base\InvalidCallException();
     }
     $key = $this->filter->buildKey($route);
     $field = 'f' . substr($key, 0, 10);
     $model = new DynamicModel([$field]);
     $model->addRule($field, 'required');
     if ($model->load(Yii::$app->getRequest()->post()) && $model->validate()) {
         if ($this->filter->isValid($model->{$field}, $route)) {
             $this->filter->setValid($route);
             return Yii::$app->getResponse()->redirect($returnUrl);
         } else {
             $model->addError($field, $this->filter->message);
         }
     }
     return $this->render($this->viewFile, ['model' => $model, 'field' => $field]);
 }
开发者ID:mdmsoft,项目名称:yii2-action-filter,代码行数:25,代码来源:VerifyController.php

示例4: run

    public function run()
    {
        $data = ['name', 'email', 'text'];
        $model_feedback = new DynamicModel($data);
        $model_feedback->addRule('name', 'required');
        $model_feedback->addRule('email', 'required');
        $model_feedback->addRule('text', 'required');
        $model_feedback->addRule('email', 'email');

        if (Yii::$app->request->isPost) {
            if ($model_feedback->load(Yii::$app->request->post()) && $model_feedback->validate()) {
                Yii::$app->common->sendMail('Subject Advert', $model_feedback->text);
            }
        }

        $current_user = ['email' => '', 'username' => ''];

        if (!Yii::$app->user->isGuest) {
            $current_user['email'] = Yii::$app->user->identity->email;
            $current_user['username'] = Yii::$app->user->identity->username;
        }

        return $this->render('feedback', [
            'model_feedback' => $model_feedback,
            'current_user' => $current_user
        ]);
    }
开发者ID:scorp7mix,项目名称:yii,代码行数:27,代码来源:FeedbackWidget.php

示例5: actionLanguage

 public function actionLanguage()
 {
     $model = new DynamicModel(['language']);
     $model->addRule(['language'], 'required');
     $model->setAttributes(['language' => Yii::$app->session->get('language', 'en')]);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         Yii::$app->session->set('language', $model->language);
         return $this->redirect(['db-config']);
     }
     return $this->render('language', ['languages' => InstallerHelper::getLanguagesArray(), 'model' => $model]);
 }
开发者ID:lzpfmh,项目名称:dotplant2,代码行数:11,代码来源:InstallerController.php

示例6: actionIndex

 /**
  * Lists all Post models.
  * @return mixed
  */
 public function actionIndex()
 {
     $postSearchForm = new DynamicModel(['search']);
     $postSearchForm->addRule('search', 'string', ['length' => [3, 255], 'tooShort' => 'Поиск должен содержать минимум 3 символа.']);
     $query = Post::find()->distinct()->joinWith('categories')->where(['post.status' => 1])->orderBy('created DESC');
     $request = Yii::$app->request;
     $query->filterWhere(['category_id' => $request->getQueryParam('category')]);
     if ($postSearchForm->load($request->queryParams, '') && $postSearchForm->validate()) {
         $query->andFilterWhere(['OR', ['LIKE', 'title', $request->getQueryParam('search')], ['LIKE', 'anotation', $request->getQueryParam('search')], ['LIKE', 'text', $request->getQueryParam('search')]]);
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 3]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('index', ['models' => $models, 'pages' => $pages, 'postSearchForm' => $postSearchForm]);
 }
开发者ID:obuhovski,项目名称:my-site,代码行数:19,代码来源:PostController.php

示例7: actionIndex

 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Job::find(), 'pagination' => ['pageSize' => 1]]);
     $model = new DynamicModel(['search_keyword', 'search_location', 'search_type']);
     $model->addRule('search_type', 'integer')->addRule('search_location', 'string', ['max' => 128])->addRule('search_keyword', 'string', ['max' => 128]);
     if ($model->load(Yii::$app->request->post())) {
         switch ($model->search_type) {
             case Lookup::item_code('SearchType', 'Organizations'):
                 return $this->redirect(['organization/index', 'search_keyword' => $model->search_keyword]);
                 break;
             case Lookup::item_code('SearchType', 'Opportunities'):
                 return $this->redirect(['job/index', 'search_keyword' => $model->search_keyword]);
                 break;
             default:
                 throw new NotFoundHttpException('Your search:' . $model->search_keyword);
                 break;
         }
     }
     return $this->render('index', ['model' => $model, 'dataProvider' => $dataProvider]);
 }
开发者ID:kapilbhadke,项目名称:ConnectMe,代码行数:20,代码来源:SiteController.php

示例8: actionIndex

 /**
  * Lists all Setting models.
  * @return mixed
  */
 public function actionIndex()
 {
     $tabs = (new Query())->select('group')->from('{{%core_setting}}')->orderBy('key_order')->distinct()->column();
     $attributes = (new Query())->select('key')->from('{{%core_setting}}')->orderBy('key_order')->column();
     //var_dump($tabs);
     $model = new DynamicModel($attributes);
     $settings = [];
     foreach ($attributes as $attribute) {
         $setting = Setting::find()->where(['key' => $attribute])->asArray()->one();
         $settings[$setting['group']][$attribute] = $setting;
         $model->{$attribute} = $setting['value'];
         //$model->la
         if (!empty($rules = json_decode($setting['rules'], true))) {
             foreach ($rules as $rule => $conf) {
                 //var_dump($conf);
                 $model->addRule($attribute, $rule, $conf);
             }
         } else {
             $model->addRule($attribute, 'required');
         }
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         foreach ($attributes as $attribute) {
             $s = Setting::findOne($attribute);
             $s->value = $model->{$attribute};
             if ($s->save(false)) {
                 Yii::$app->session->setFlash('success', Yii::t('app', 'Settings saved successfully.'));
             } else {
                 Yii::$app->session->setFlash('error', Yii::t('app', 'Sorry, something went wrong. {ERRORS}.', ['ERRORS' => json_encode($s->errors)]));
                 break;
             }
         }
         return $this->redirect(['index']);
     }
     return $this->render('index', ['model' => $model, 'settings' => $settings, 'tabs' => $tabs]);
 }
开发者ID:modernkernel,项目名称:yii2-skeleton,代码行数:40,代码来源:SettingController.php

示例9: actionViewAdvert

 public function actionViewAdvert($id)
 {
     $model = Advert::findOne($id);
     $data = ['name', 'email', 'text'];
     $model_feedback = new DynamicModel($data);
     $model_feedback->addRule('name', 'required');
     $model_feedback->addRule('email', 'required');
     $model_feedback->addRule('text', 'required');
     $model_feedback->addRule('email', 'email');
     if (\Yii::$app->request->isPost) {
         if ($model_feedback->load(\Yii::$app->request->post()) && $model_feedback->validate()) {
             \Yii::$app->common->sendMail('Subject Advert', $model_feedback->text);
         }
     }
     $user = $model->user;
     $images = Common::getImageAdvert($model, false);
     $current_user = ['email' => '', 'username' => ''];
     if (!\Yii::$app->user->isGuest) {
         $current_user['email'] = \Yii::$app->user->identity->email;
         $current_user['username'] = \Yii::$app->user->identity->username;
     }
     return $this->render('view_advert', ['model' => $model, 'model_feedback' => $model_feedback, 'user' => $user, 'images' => $images, 'current_user' => $current_user]);
 }
开发者ID:pers1307,项目名称:yii,代码行数:23,代码来源:MainController.php

示例10: actionChangeBranch

 public function actionChangeBranch()
 {
     $model = new DynamicModel(['selected' => Yii::$app->user->branch]);
     $model->addRule('selected', 'safe');
     $ids = UserToBranch::find()->select('id_branch')->where(['id_user' => Yii::$app->user->id])->column();
     $branchs = Branch::findAll(['id_branch' => $ids]);
     if ($model->load(Yii::$app->request->post())) {
         Yii::$app->user->branch = $model->selected;
     }
     return $this->render('change-branch', ['model' => $model, 'branchs' => $branchs]);
 }
开发者ID:jimminababan,项目名称:sangkilbiz3,代码行数:11,代码来源:UserToBranchController.php

示例11: actionTempFile

 public function actionTempFile()
 {
     $model = new DynamicModel(['nama', 'file_id']);
     // behavior untuk upload file
     $model->attachBehavior('upload', ['class' => 'mdm\\upload\\UploadBehavior', 'attribute' => 'file', 'savedAttribute' => 'file_id']);
     // rule untuk model
     $model->addRule('nama', 'string')->addRule('file', 'file', ['extensions' => 'txt']);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->saveUploadedFile() !== false) {
             Yii::$app->session->setFlash('success', 'Upload Sukses');
         }
     }
     return $this->render('upload-manifest', ['model' => $model]);
 }
开发者ID:Ent-ch,项目名称:stock_auto,代码行数:14,代码来源:DataImportController.php

示例12: 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)]);
 }
开发者ID:s1dex,项目名称:Booking,代码行数:36,代码来源:TourController.php


注:本文中的yii\base\DynamicModel::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。