public function actionAdditem($pid, $Stre_page = 1) { $cs = Yii::app()->clientScript; $cs->registerScriptFile("/js/admin/url.js"); $model = new Stre(); $model->type_id = isset($_POST['Stre']['type_id']) ? $_POST['Stre']['type_id'] : null; $root = Stre::model()->roots()->findByPk($pid); $this->performAjaxValidation($model); if (!empty($_POST['Stre']['name'])) { //print_r($_POST['AttrVal'][18]); //exit(); $model->attributes = $_POST['Stre']; $parent = Stre::model()->findByPk($_POST['Stre']['root']); try { $model->appendTo($parent); $attrs = $model->type->attrs; foreach ($attrs as $attr) { $attr_val = new AttrVal(); $attr_val->id_attr = $attr->id; $attr_val->id_elem = $model->id; $attr_val->value = $_POST['AttrVal'][$attr->id]; if ($attr->fk > 0) { if (!empty($attr_val->value)) { $attr_val->value = implode(',', $_POST['AttrVal'][$attr->id]); } else { $attr_val->value = ''; } } if ($attr->mytype->mytype == 'photo' && !empty($_POST['AttrVal'][$attr->id])) { $photo = $_POST['AttrVal'][$attr->id]; $img = Yii::app()->image->load($_SERVER['DOCUMENT_ROOT'] . '/userfiles/editor/images/' . $photo); $pname = 'catalog_' . $model->id . '_' . $photo; $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/original/' . $pname); $img->resize(600, 600); $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/large/' . $pname); $img->resize(200, 200); $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/medium/' . $pname); $img->resize(100, 100); $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/small/' . $pname); $attr_val->value = $pname; } $attr_val->save(); } } catch (CDbException $e) { $this->redirect($this->createUrl('default/viewcatalog', array('id' => $pid, 'Stre_page' => $Stre_page, 'msg' => $e->getMessage(), 'msgtype' => 'error'))); } if (isset($_POST['savebutton'])) { $this->redirect($this->createUrl('default/viewcatalog', array('id' => $pid, 'Stre_page' => $Stre_page, 'msg' => '[!] Элемент успешно создан', 'msgtype' => 'success'))); } else { $this->redirect($this->createUrl('default/update', array('id' => $model->id, 'pid' => $pid, 'Stre_page' => $Stre_page, 'msg' => '[!] Элемент успешно создан', 'msgtype' => 'success'))); } } $this->render('additem', array('root' => $root, 'model' => $model, 'pid' => $pid, 'Stre_page' => $Stre_page)); }
/** * 编辑:内容关联属性 * * @param [type] $postId [description] * @param [type] $attrData [description] * @return [type] [description] */ public static function xupdate($postId, $attrData) { foreach ((array) $attrData as $key => $row) { $val = is_array($row['val']) ? implode(',', $row['val']) : $row['val']; if ($val) { $attrVal = AttrVal::model()->find('post_id=:postId AND attr_id=:attrId', array('postId' => $postId, 'attrId' => $row['id'])); if ($attrVal) { $attrVal->post_id = $postId; $attrVal->attr_id = $row['id']; $attrVal->attr_name = $row['name']; $attrVal->attr_val = $val; $attrVal->save(); } else { $attrValModel = new AttrVal(); $attrValModel->post_id = $postId; $attrValModel->attr_id = $row['id']; $attrValModel->attr_name = $row['name']; $attrValModel->attr_val = $val; $attrValModel->save(); } } } }