當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Category::loadDefaultValues方法代碼示例

本文整理匯總了PHP中app\modules\shop\models\Category::loadDefaultValues方法的典型用法代碼示例。如果您正苦於以下問題:PHP Category::loadDefaultValues方法的具體用法?PHP Category::loadDefaultValues怎麽用?PHP Category::loadDefaultValues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\modules\shop\models\Category的用法示例。


在下文中一共展示了Category::loadDefaultValues方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: createCategory

 private function createCategory($name, $parent_id)
 {
     $model = new Category();
     $model->loadDefaultValues();
     $model->name = $name;
     $model->parent_id = $parent_id;
     $model->slug = Helper::createSlug($model->name);
     $model->save();
     return $model;
 }
開發者ID:tqsq2005,項目名稱:dotplant2,代碼行數:10,代碼來源:DemoDataController.php

示例2: 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::loadDefaultValues方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。