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


PHP Attribute::save方法代码示例

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


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

示例1: save

 /**
  * 新商品
  */
 public function save()
 {
     $item = new Attribute();
     $item->cat_id = Input::get('cat_id');
     $item->name = Input::get('name');
     $item->save();
     return redirect()->route('admin.attribute.index');
 }
开发者ID:cdandy,项目名称:artup,代码行数:11,代码来源:ItemCatController.php

示例2: actionCreate

 /**
  * Создает новую модель атрибута.
  * Если создание прошло успешно - перенаправляет на просмотр.
  *
  * @return void
  */
 public function actionCreate()
 {
     $model = new Attribute();
     if (($data = Yii::app()->getRequest()->getPost('Attribute')) !== null) {
         $model->setAttributes($data);
         if ($model->save() && $model->setTypes(Yii::app()->getRequest()->getPost('types', [])) && $model->setMultipleValuesAttributes(explode(PHP_EOL, $model->rawOptions))) {
             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('StoreModule.store', 'Attribute created'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create']));
         }
     }
     $this->render('create', ['model' => $model, 'types' => Type::model()->findAll()]);
 }
开发者ID:yupe,项目名称:yupe,代码行数:18,代码来源:AttributeBackendController.php

示例3: actionCreate

 /**
  * Создает новую модель атрибута.
  * Если создание прошло успешно - перенаправляет на просмотр.
  *
  * @return void
  */
 public function actionCreate()
 {
     $model = new Attribute();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (($data = Yii::app()->getRequest()->getPost('Attribute')) !== null) {
         $model->setAttributes($data);
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('StoreModule.attribute', 'Атрибут создан.'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create']));
         }
     }
     $this->render('create', ['model' => $model]);
 }
开发者ID:RonLab1987,项目名称:43berega,代码行数:20,代码来源:AttributeBackendController.php

示例4: save

 public function save()
 {
     $attribute = Attribute::model()->findByPk($this->id);
     if (is_null($attribute)) {
         // is insert
         $attribute = new Attribute();
         $attribute->attribute_group_id = $this->group;
         $attribute->sort_order = $this->sortOrder;
         $attribute->save();
         $attributeDescription = new AttributeDescription();
         $attributeDescription->attribute_id = $attribute->attribute_id;
         $attributeDescription->language_id = 1;
         // TODO: read locale
         $attributeDescription->name = $this->name;
         $attributeDescription->save();
     } else {
         $attribute->attribute_group_id = $this->group;
         $attribute->sort_order = $this->sortOrder;
         $attribute->save();
         $attribute->description->name = $this->name;
         $attribute->description->save();
     }
 }
开发者ID:damnpoet,项目名称:yiicart,代码行数:23,代码来源:AttributeForm.php

示例5: actionCreate

 public function actionCreate()
 {
     $model = new Attribute();
     if (isset($_POST['Attribute'])) {
         $model->setAttributes($_POST['Attribute']);
         if ($model->save()) {
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->end();
             } else {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:hanihh,项目名称:vvs_v2,代码行数:15,代码来源:AttributeController.php

示例6: doSave

 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCartItem !== null) {
             if ($this->aCartItem->isModified() || $this->aCartItem->isNew()) {
                 $affectedRows += $this->aCartItem->save($con);
             }
             $this->setCartItem($this->aCartItem);
         }
         if ($this->aAttribute !== null) {
             if ($this->aAttribute->isModified() || $this->aAttribute->isNew()) {
                 $affectedRows += $this->aAttribute->save($con);
             }
             $this->setAttribute($this->aAttribute);
         }
         if ($this->aAttributeAv !== null) {
             if ($this->aAttributeAv->isModified() || $this->aAttributeAv->isNew()) {
                 $affectedRows += $this->aAttributeAv->save($con);
             }
             $this->setAttributeAv($this->aAttributeAv);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
开发者ID:bcbrr,项目名称:LegacyProductAttributes,代码行数:53,代码来源:LegacyCartItemAttributeCombination.php

示例7: actionCreate

 public function actionCreate()
 {
     $model = new DatasetAttributes();
     $att = Attribute::model()->findByAttributes(array('attribute_name' => Attribute::FUP));
     if (!$att) {
         $att = new Attribute();
         $att->attribute_name = Attribute::FUP;
         $att->definition = '';
         $att->save();
     }
     $model->attribute_id = $att->id;
     $image = new Images();
     if (isset($_POST['DatasetAttributes'])) {
         $args = $_POST['DatasetAttributes'];
         $exist = DatasetAttributes::model()->findByAttributes(array('dataset_id' => $args['dataset_id'], 'attribute_id' => $att->id));
         if ($exist) {
             $model = $exist;
         }
         $model->attributes = $args;
         $model->value = '';
         //$image->attributes = $_POST['Images'];
         $image->license = "no license";
         $image->photographer = "no author";
         $image->source = "gigadb";
         if ($image->validate()) {
             $image->save();
         } else {
             Yii::log(print_r($image->getErrors(), true), 'debug');
         }
         if ($image) {
             $model->image_id = $image->id;
         }
         if ($model->validate()) {
             $model->save();
             $this->redirect('/dataset/' . $model->dataset->identifier);
         } else {
             Yii::log(print_r($model->getErrors(), true), 'debug');
         }
     }
     $this->render('create', array('model' => $model, 'image' => $image));
 }
开发者ID:jessesiu,项目名称:GigaDBV3,代码行数:41,代码来源:PolicyController.php

示例8: actionCreate

 public function actionCreate()
 {
     $model = new Attribute();
     $description = new AttributeDescription();
     $this->performAjaxValidation(array($model, $description), 'attribute-form');
     if (isset($_POST[$this->modelName])) {
         $model->setAttributes($_POST[$this->modelName]);
         $description->setAttributes($_POST[$this->modelName . 'Description']);
         $suc = Yii::t('info', 'Attribute was successfully created');
         $err = Yii::t('info', 'Could not update Attribute');
         $description->attribute_id = 0;
         $description->locale_code = Yii::app()->getLanguage();
         if ($model->validate() && $description->validate()) {
             if ($model->save()) {
                 $description->attribute_id = $model->id;
                 $description->save();
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc);
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_view', array('model' => $model, 'description' => $description), false, true);
                     Yii::app()->end();
                 } else {
                     $this->redirect(array('view', 'id' => $model->id));
                 }
             } else {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err);
             }
         } else {
             $description->validate();
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form', array('model' => $model, 'description' => $description), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'description' => $description));
 }
开发者ID:Rudianasaja,项目名称:cycommerce,代码行数:36,代码来源:AttributeController.php

示例9: actionCreate

    public function actionCreate()
    {
        $model = new Attribute;
        $lang_model = new LanguageModel;
        $AttrDescModel = new AttributeDescription;
        $ValueModel = new Value;
        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        $allLangs = $lang_model->findAll('1', array('order' => 'id ASC'));

        $allLangsJS = array();
        foreach ($allLangs as $language) {
            $allLangsJS[$language['id']] = $language['code'];
        }

        if (isset($_POST['Attribute'])) {
            $model->attributes = $_POST['Attribute'];
            if ($model->save()) {
                $pk = $model->getPrimaryKey();
                foreach ($_POST['AttributeDescription']['attribute_name'] as $langId => $attrName) {
                    $attr_desc_model = new AttributeDescription;
                    $attr_desc_model->attributes = array(
                        'attribute_id' => $pk,
                        'attribute_name' => $attrName,
                        'language_id' => $langId,
                    );
                    $attr_desc_model->save();
                }
                if (isset($_POST['NewAttrValue'])) {
                    foreach ($_POST['NewAttrValue'] as $spec_id => $new_val) {
                        $ValueModel = new Value;
                        $ValueModel->attributes = array(
                            'status' => 1,
                        );
                        $ValueModel->save();
                        $v_id = $ValueModel->getPrimaryKey();

                        foreach ($new_val as $lang_id => $value) {
                            if ($value != '') {
                                $ValueDescription = new ValueDescription;
                                $ValueDescription->attributes = array(
                                    'value_id' => $v_id,
                                    'language_id' => $lang_id,
                                    'value_name' => $value,
                                );
                                $ValueDescription->save();
                            }
                        }

                        $Attribute2value = new Attribute2value;
                        $Attribute2value->attributes = array('attribute_id' => $pk, 'value_id' => $v_id);
                        $Attribute2value->save();
                    }
                }
                $this->redirect(array('index'));
            }
        }

        $this->render('create', array(
            'model' => $model,
            'allLangs' => $allLangs,
            'AttrDescModel' => $AttrDescModel,
            'allLangsJS' => json_encode($allLangsJS),
        ));
    }
开发者ID:Kostiantin,项目名称:floors,代码行数:66,代码来源:AttributeController.php

示例10: actionAttributeCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionAttributeCreate($class)
 {
     $model = new Attribute();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $class = $this->loadModel($class);
     $model->id_class = $class->id_class;
     if (isset($_POST['Attribute'])) {
         $model->attributes = $_POST['Attribute'];
         if ($model->save()) {
             $this->redirect(array('attributeview', 'id' => $model->id_attribute));
         }
     }
     $this->render('attribute/create', array('model' => $model, 'class' => $class));
 }
开发者ID:black2279,项目名称:Tracy-openshift,代码行数:19,代码来源:ClassController.php

示例11: actionAddSampleAttr

 public function actionAddSampleAttr()
 {
     if (isset($_POST['sample_id']) && isset($_POST['attr_id']) && isset($_POST['attr_value']) && isset($_POST['attr_unit'])) {
         if (strlen($_POST['attr_id']) < 3) {
             Util::returnJSON(array("success" => false, "message" => Yii::t("app", "Please enter an Attribute name with more than 3 characters.")));
         }
         $lastSa = SampleAttribute::model()->find(array('order' => 'id desc'));
         $sa = new SampleAttribute();
         if ($lastSa) {
             $sa->id = $lastSa->id + 1;
         }
         // try to find attribute, if not found, create a new one
         $attr = Attribute::model()->findByAttributes(array('attribute_name' => $_POST['attr_id']));
         if (!$attr) {
             #create new attribute
             $attr = new Attribute();
             $attr->attribute_name = $_POST['attr_id'];
             $attr->save(false);
         }
         $sa->sample_id = $_POST['sample_id'];
         $sa->attribute_id = $attr->id;
         $sa->value = $_POST['attr_value'];
         if (isset($_POST['attr_unit']) && $_POST['attr_unit'] != "") {
             $sa->unit_id = $_POST['attr_unit'];
         }
         if ($sa->save()) {
             Util::returnJSON(array("success" => true));
         }
         Util::returnJSON(array("success" => false, "message" => Yii::t("app", "Cannot add sample attr.")));
     }
 }
开发者ID:jessesiu,项目名称:GigaDBV3,代码行数:31,代码来源:AdminDatasetSampleController.php

示例12: updateSampleAttributes

 /**
  * Upate sample attribute
  * 
  * @param Sample $model
  */
 private function updateSampleAttributes($model)
 {
     // delete first all the sample Attribute
     SampleAttribute::model()->deleteAllByAttributes(array('sample_id' => $model->id));
     if (trim($model->attributesList)) {
         // From a model we will clone
         $sampleAttr = new SampleAttribute();
         $sampleAttr->sample_id = $model->id;
         foreach (explode(',', $model->attributesList) as $sAttr) {
             $sAttr = str_replace('"', '', $sAttr);
             $data = explode('=', $sAttr);
             if (count($data) == 2) {
                 // Get attribute, if not exist we create
                 $attribute = Attribute::model()->findByAttributes(array('structured_comment_name' => trim($data[0])));
                 if (!$attribute) {
                     $attribute = new Attribute();
                     $attribute->structured_comment_name = trim($data[0]);
                     $attribute->attribute_name = str_replace('_', ' ', trim($data[0]));
                     $attribute->definition = str_replace('_', ' ', trim($data[0]));
                     $attribute->save();
                 }
                 // Let's save the new sample attribute
                 $sampleAttribute = clone $sampleAttr;
                 $sampleAttribute->value = trim($data[1]);
                 $sampleAttribute->attribute_id = $attribute->id;
                 $sampleAttribute->save();
             }
         }
     }
 }
开发者ID:jessesiu,项目名称:GigaDBV3,代码行数:35,代码来源:AdminSampleController.php

示例13: saveSpec

 public function saveSpec($spec, $product_id, $category_id, $type_id)
 {
     $name = \yupe\helpers\YText::translit($spec['name']);
     if (!in_array($name, $this->attr_name)) {
         if ($category_id) {
             // добавим в характеристику id категории
             $name = $name . $category_id;
         } else {
             print_r(" Error: can`t find StoreCategory for {$spec['id_product']} \n");
             return;
         }
     }
     $model = Attribute::model()->findByAttributes(['name' => $name]);
     if (!$model) {
         $model = new Attribute();
         $model->group_id = 1;
         $model->name = $name;
         $model->title = $spec['name'];
         $model->type = Attribute::TYPE_DROPDOWN;
         if ($model->save()) {
             $option = new AttributeOption();
             $option->attribute_id = $model->id;
             $option->position = 0;
             $option->value = $spec['value'];
             if (!$option->save()) {
                 echo "\n";
                 echo "Error: save AttributeOption for {$name} \n";
                 echo "\n";
             }
             $TypeAttribute = new TypeAttribute();
             $TypeAttribute->type_id = $type_id;
             $TypeAttribute->attribute_id = $model->id;
             if (!$TypeAttribute->save()) {
                 echo "\n";
                 echo "Error: save TypeAttribute for {$name} \n";
                 echo "\n";
             }
         } else {
             echo "\n";
             echo "Error: save Attribute for {$name} \n";
             echo "\n";
             return;
         }
     } else {
         $this->addOption($spec, $model);
     }
     // свяжем продукт со значением характеристики
     $option = AttributeOption::model()->findByAttributes(['attribute_id' => $model->id, 'value' => $spec['value']]);
     if ($option) {
         $id = $option->id;
         $name = $model->name;
         $command = \Yii::app()->db->createCommand("\n                INSERT INTO `site_store_product_attribute_eav` (`product_id`, `attribute`, `value`) \n                VALUES ({$product_id}, '{$name}', {$id})\n            ")->execute();
     }
 }
开发者ID:alexanderkuz,项目名称:test-yii2,代码行数:54,代码来源:ImportBaseTiuCommand.php


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