本文整理汇总了PHP中common\models\Category::parent方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::parent方法的具体用法?PHP Category::parent怎么用?PHP Category::parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Category
的用法示例。
在下文中一共展示了Category::parent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
if (!$this->is_access('category/create')) {
Yii::$app->session->setFlash('error', $this->errorInfo);
return $this->redirect($this->redirectUrl);
}
$model = new Category();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
// 加入分类推荐
$CatRecommend = new CatRecommend();
$CatRecommend->insertRecommend($model->cat_id, $_POST['Category']['recommend_type']);
// 是否需要显示在导航栏
if ($model->show_in_nav == 1) {
$Nav = new Nav();
$Nav->addData('c', $model->cat_id);
}
Yii::$app->session->setFlash('success', '添加成功');
return $this->redirect(['index']);
} else {
Yii::$app->view->params['meta_title'] = '添加分类';
$catList = $model->parent(0);
return $this->render('create', ['model' => $model, 'catList' => $catList]);
}
}
示例2: actionUpdate
/**
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
if (!$this->is_access('goods/update')) {
Yii::$app->session->setFlash('error', $this->errorInfo);
return $this->redirect($this->redirectUrl);
}
$model = $this->findModel($id);
$GoodsGallery = new GoodsGallery();
$post = Yii::$app->request->post();
if ($model->load($post)) {
$GoodsGallery->load($post);
if ($model->validate() && $GoodsGallery->validate()) {
// 商品封面图片
if ($_FILES['Goods']['error']['goods_img'] === 0) {
$model->goods_img = File::uploadImage($model, 'goods_img', 'shop');
$model->goods_thumb = Images::thumb('./' . $model->goods_img, 250, 250);
}
if ($model->save(false)) {
// 商品相册
if ($_FILES['GoodsGallery']['error']['img_url'][0] === 0) {
$img_url = File::uploadImages($GoodsGallery, 'img_url', 'goods');
$GoodsGallery->addData($model->goods_id, $img_url);
}
// 商品属性
GoodsAttr::addData($model->goods_id);
}
Yii::$app->session->setFlash('success', '编辑成功');
}
return $this->redirect(['index']);
} else {
// 商品分类
$Category = new Category();
$categoryList = $Category->parent(0, false);
// 品牌
$Brand = new Brand();
$brandList = $Brand->getLists();
// 商品类型
$GoodsType = new GoodsType();
$goodsTypeList = $GoodsType->dropList();
// 相册
$goodsGalleryList = $GoodsGallery->getGoodsGallery($id);
Yii::$app->view->params['meta_title'] = '编辑商品';
return $this->render('update', ['model' => $model, 'GoodsGallery' => $GoodsGallery, 'categoryList' => $categoryList, 'brandList' => $brandList, 'goodsTypeList' => $goodsTypeList, 'goodsGalleryList' => $goodsGalleryList]);
}
}