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


PHP Category::save方法代码示例

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


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

示例3: up


//.........这里部分代码省略.........
            echo "INFO: Using admin user details provided by ENV variables...\n";
            $username = getenv("ADMIN_USERNAME");
            $email = getenv("ADMIN_EMAIL");
            $password = getenv("ADMIN_PASSWORD");
        } else {
            $stdIn = fopen("php://stdin", "r");
            do {
                echo 'Enter admin username (3 or more chars): ';
                $username = trim(fgets($stdIn));
            } while (mb_strlen($username) < 3);
            do {
                echo 'Enter admin email: ';
                $email = trim(fgets($stdIn));
            } while (preg_match('#^\\w[\\w\\d\\.\\-_]*@[\\w\\d\\.\\-_]+\\.\\w{2,6}$#i', $email) != 1);
            do {
                do {
                    echo 'Enter admin password (8 or more chars): ';
                    $password = trim(fgets($stdIn));
                } while (mb_strlen($password) < 8);
                do {
                    echo 'Confirm admin password: ';
                    $confirmPassword = trim(fgets($stdIn));
                } while (mb_strlen($confirmPassword) < 8);
                if ($password != $confirmPassword) {
                    echo "Password does not match the confirm password\n";
                }
            } while ($password != $confirmPassword);
            fclose($stdIn);
        }
        $user = new User(['scenario' => 'signup']);
        $user->username = $username;
        $user->password = $password;
        $user->email = $email;
        $user->save(false);
        if (getenv("INSTALL_RUSSIAN_TRANSLATIONS")) {
            echo "INFO: Using translations details provided by ENV variables...\n";
            if (trim(strtolower(getenv("INSTALL_RUSSIAN_TRANSLATIONS"))) === 'y') {
                Yii::$app->language = 'ru-RU';
            }
        } else {
            $f = fopen('php://stdin', 'r');
            echo "Install Russian translations? [y/N] ";
            while (true) {
                $answer = trim(fgets($f));
                if ($answer === 'y' || $answer === 'Y') {
                    Yii::$app->language = 'ru-RU';
                    break;
                } elseif ($answer === 'n' || $answer === 'N') {
                    break;
                }
                echo "Install Russian translations? [y/N]";
            }
            fclose($f);
        }
        $this->batchInsert('{{%auth_item}}', ['name', 'type', 'description'], [['admin', '1', Yii::t('app', 'Administrator')], ['manager', '1', Yii::t('app', 'Manager')], ['administrate', '2', Yii::t('app', 'Administrate panel')], ['api manage', '2', Yii::t('app', 'API management')], ['seo manage', '2', Yii::t('app', 'SEO management')], ['task manage', '2', Yii::t('app', 'Task management')], ['user manage', '2', Yii::t('app', 'User management')], ['cache manage', '2', Yii::t('app', 'Cache management')], ['content manage', '2', Yii::t('app', 'Content management')], ['shop manage', '2', Yii::t('app', 'Shop management')], ['order manage', '2', Yii::t('app', 'Order management')], ['category manage', '2', Yii::t('app', 'Category management')], ['product manage', '2', Yii::t('app', 'Product management')], ['property manage', '2', Yii::t('app', 'Property management')], ['view manage', '2', Yii::t('app', 'View management')], ['review manage', '2', Yii::t('app', 'Review management')], ['navigation manage', '2', Yii::t('app', 'Navigation management')], ['form manage', '2', Yii::t('app', 'Form management')], ['media manage', '2', Yii::t('app', 'Media management')], ['order status manage', '2', Yii::t('app', 'Order status management')], ['payment manage', '2', Yii::t('app', 'Payment type management')], ['shipping manage', '2', Yii::t('app', 'Shipping option management')], ['newsletter manage', '2', Yii::t('app', 'Newsletter management')], ['monitoring manage', '2', Yii::t('app', 'Monitoring management')], ['data manage', '2', Yii::t('app', 'Data management')], ['setting manage', '2', Yii::t('app', 'Setting management')]]);
        $this->batchInsert('{{%auth_item_child}}', ['parent', 'child'], [['shop manage', 'category manage'], ['shop manage', 'product manage'], ['shop manage', 'order manage'], ['manager', 'administrate'], ['manager', 'content manage'], ['manager', 'order manage'], ['manager', 'shop manage'], ['manager', 'category manage'], ['manager', 'product manage'], ['manager', 'property manage'], ['manager', 'view manage'], ['manager', 'review manage'], ['manager', 'navigation manage'], ['manager', 'form manage'], ['manager', 'media manage'], ['admin', 'administrate'], ['admin', 'api manage'], ['admin', 'order manage'], ['admin', 'seo manage'], ['admin', 'task manage'], ['admin', 'user manage'], ['admin', 'cache manage'], ['admin', 'content manage'], ['admin', 'shop manage'], ['admin', 'category manage'], ['admin', 'product manage'], ['admin', 'property manage'], ['admin', 'view manage'], ['admin', 'review manage'], ['admin', 'navigation manage'], ['admin', 'form manage'], ['admin', 'media manage'], ['admin', 'order status manage'], ['admin', 'payment manage'], ['admin', 'shipping manage'], ['admin', 'monitoring manage'], ['admin', 'newsletter manage'], ['admin', 'data manage'], ['admin', 'setting manage']]);
        $this->insert('{{%auth_assignment}}', ['item_name' => 'admin', 'user_id' => $user->id]);
        // demo data
        $demo = null;
        if (getenv("INSTALL_DEMO_DATA")) {
            $demo = getenv("INSTALL_DEMO_DATA");
        } else {
            $stdIn = fopen("php://stdin", "r");
            do {
                echo 'Do you want to install demo data [y/n]: ';
                $demo = strtolower(trim(fgets($stdIn)));
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:67,代码来源:m141023_084857_init.php


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