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


PHP Category::validate方法代码示例

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


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

示例1: actionEdit

 public function actionEdit($parent_id = null, $id = null)
 {
     if (null === $parent_id) {
         throw new NotFoundHttpException();
     }
     if (null === ($object = Object::getForClass(Category::className()))) {
         throw new ServerErrorHttpException();
     }
     /** @var null|Category|HasProperties $model */
     $model = null;
     if (null !== $id) {
         $model = Category::findById($id, null, null);
     } else {
         $parent = Category::findById($parent_id, null, null);
         if ($parent_id === '0' || !is_null($parent)) {
             $model = new Category();
             $model->loadDefaultValues();
             $model->parent_id = $parent_id;
             if ($parent_id !== '0') {
                 $model->category_group_id = $parent->category_group_id;
             }
         } else {
             throw new ServerErrorHttpException();
         }
     }
     if (null === $model) {
         throw new ServerErrorHttpException();
     }
     $event = new BackendEntityEditEvent($model);
     $this->trigger(self::BACKEND_CATEGORY_EDIT, $event);
     $post = \Yii::$app->request->post();
     if ($event->isValid && $model->load($post) && $model->validate()) {
         $saveStateEvent = new BackendEntityEditEvent($model);
         $this->trigger(self::BACKEND_CATEGORY_EDIT_SAVE, $saveStateEvent);
         $save_result = $model->save();
         $model->saveProperties($post);
         if (null !== ($view_object = ViewObject::getByModel($model, true))) {
             if ($view_object->load($post, 'ViewObject')) {
                 if ($view_object->view_id <= 0) {
                     $view_object->delete();
                 } else {
                     $view_object->save();
                 }
             }
         }
         if ($save_result) {
             $modelAfterSaveEvent = new BackendEntityEditEvent($model);
             $this->trigger(self::BACKEND_CATEGORY_AFTER_SAVE, $modelAfterSaveEvent);
             $this->runAction('save-info', ['model_id' => $model->id]);
             Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been saved'));
             $returnUrl = Yii::$app->request->get('returnUrl', ['index']);
             switch (Yii::$app->request->post('action', 'save')) {
                 case 'next':
                     return $this->redirect(['edit', 'returnUrl' => $returnUrl, 'parent_id' => Yii::$app->request->get('parent_id', null)]);
                 case 'back':
                     return $this->redirect($returnUrl);
                 default:
                     return $this->redirect(Url::toRoute(['edit', 'id' => $model->id, 'returnUrl' => $returnUrl, 'parent_id' => $model->parent_id]));
             }
         } else {
             throw new ServerErrorHttpException();
         }
     }
     return $this->render('category-form', ['model' => $model, 'object' => $object]);
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:65,代码来源:BackendCategoryController.php


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