本文整理汇总了PHP中common\models\Category类的典型用法代码示例。如果您正苦于以下问题:PHP Category类的具体用法?PHP Category怎么用?PHP Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionView
/**
* Просмотр списка постов по тегу
* @param $id
* @return string
*/
public function actionView($id)
{
$tagModel = new Tags();
$tag = $tagModel->getTag($id);
$categoryModel = new Category();
return $this->render('view', ['tag' => $tag, 'posts' => $tag->getTagPosts(), 'categories' => $categoryModel->getCategories()]);
}
示例2: actionLoadGoods
public function actionLoadGoods($id, $category = 'all', $q = '')
{
$offset = (int) Yii::$app->request->post('offset');
Yii::$app->response->format = Response::FORMAT_JSON;
/* @var $model Store */
$model = Store::findOne(['id' => $id, 'status' => [Store::STATUS_ACTIVE, Store::STATUS_REST]]);
if (!$model) {
throw new NotFoundHttpException('未找到该营业点!');
}
if ($q !== '') {
$query = $model->getGoods()->andWhere(['or', ['like', 'name', $q], ['like', 'description', $q]]);
} else {
$modelCate = $category === 'all' ? null : Category::findOne(['slug' => $category]);
if ($modelCate) {
$query = $model->getGoods($modelCate->id);
} else {
$query = $model->getGoods();
}
}
$limit = 8;
$goodsList = $query->offset($offset)->limit($limit)->all();
$output = ['status' => 'ok', 'html' => '', 'length' => count($goodsList)];
$output['end'] = $output['length'] < $limit;
foreach ($goodsList as $goods) {
$output['html'] .= $this->renderPartial('_item', ['goods' => $goods, 'lazy' => false]);
}
return $output;
}
示例3: insertCategories
public function insertCategories($categoryIds, $beforeCount = true, $afterCount = true)
{
if (!is_array($categoryIds)) {
return false;
}
$categoryIds = array_unique($categoryIds);
$this->deleteCategories($beforeCount);
//先删除文章分类
//插入新分类
if ($categoryIds) {
foreach ($categoryIds as $v) {
if (!Category::find()->andWhere('mid=:mid', [':mid' => $v])->one()) {
continue;
}
$model = new Relationship();
$model->cid = $this->cid;
$model->mid = $v;
$model->insert(false);
if ($afterCount) {
//更新分类文章数
Category::updateAllCounters(['count' => 1], ['mid' => $v]);
}
}
}
return true;
}
示例4: actionCategory
public function actionCategory($id)
{
$backUrl = \Yii::$app->request->referrer;
$category = Category::findOne($id);
$this->layout = 'basic-category';
return $this->render('category', compact('category', 'backUrl'));
}
示例5: actionIndex
public function actionIndex($slug)
{
$query = Vidmage::find()->joinWith('vidmageCategories.category')->where(['category.slug' => $slug])->orderBy(['id' => SORT_DESC]);
$vidmages = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
$channel = Category::findOne(['slug' => $slug]);
return $this->render('index', compact('vidmages', 'channel'));
}
示例6: actionDetail
public function actionDetail($id)
{
/* @var $model Store */
$model = Store::findOne($id);
if (!$model) {
throw new BadRequestHttpException('未找到该营业点!');
}
if ($model->status === Store::STATUS_DISABLED) {
throw new BadRequestHttpException('该店铺已被禁用,请重新选择!');
}
$data['store'] = $model->toArray(['id', 'name', 'school_id', 'address', 'cellphone', 'telephone', 'notice', 'status', 'hours', 'has_book', 'has_down', 'has_gift', 'has_least', 'down_upper', 'down_val', 'gift_upper', 'gift_val', 'least_val', 'created_at']);
$data['store']['downMsg'] = $model->downMsg;
$data['store']['giftMsg'] = $model->giftMsg;
$data['categories'] = Category::getKeyValuePairs();
foreach ($data['categories'] as $key => $name) {
$goodsList = $model->getGoods($key)->all();
if ($goodsList) {
foreach ($goodsList as $goods) {
$goodsArr = $goods->toArray();
$data['goodsList'][$key][] = $goodsArr;
}
} else {
$data['goodsList'][$key] = [];
}
}
return $data;
}
示例7: addData
/**
* 其他分类需要显示在导航栏的新增方法
* @param string $ctype 其他分类表标识 a:文章分类表,c:商品分类表
* @param int $cid 其他表分类id
* @return mixed
*/
public function addData($ctype, $cid)
{
// 如果已经存在就不继续执行了
if ($this->find()->where(['ctype' => $ctype, 'cid' => $cid])->one()) {
return true;
}
switch ($ctype) {
case 'a':
// 文章分类
$this->name = ArticleCat::findOne($cid)->cat_name;
$this->url = '';
// 前台还没有做,暂时空起
break;
case 'c':
// 商品分类
$this->name = Category::findOne($cid)->cat_name;
$this->url = '';
// 前台还没有做,暂时空起
break;
default:
return false;
}
$this->ctype = $ctype;
$this->cid = $cid;
$this->type = 'middle';
if ($this->insert(false)) {
return true;
}
return false;
}
示例8: beforeSave
public function beforeSave($insert)
{
$redirectLink = new Redirect(['from' => $this->fullLink]);
if (!$this->link) {
$this->link = TranslitHelper::to($this->title);
}
if ($this->isAttributeChanged('parent') || $this->isAttributeChanged('link')) {
$this->fullLink = '';
if ($parent = $this->getParentCategory()) {
$linkParts = [$parent->link];
while ($parent = $parent->getParentCategory()) {
$linkParts[] = $parent->getRelativeLink();
}
$this->fullLink = implode('/', $linkParts) . '/';
}
$this->fullLink .= $this->link;
if ($childs = $this->getChildCategories()) {
foreach ($childs as $childCategory) {
$childCategory->fullLink = $this->fullLink . '/' . $childCategory->link;
$childCategory->save(false);
}
}
$redirectLink->to = $this->fullLink;
}
if ($redirectLink->to) {
$redirectLink->save();
}
return parent::beforeSave($insert);
// TODO: Change the autogenerated stub
}
示例9: actionView
public function actionView($id)
{
$model = $this->findModel($id);
$allCategory = Category::find()->asArray()->all();
$arrayCategoryIdName = ArrayHelper::map($allCategory, 'id', 'name');
$rootCategoryId = Category::getRootCatalogId($model->category_id, $allCategory);
$arraySameRootCategory = Category::getArraySubCatalogId($rootCategoryId, $allCategory);
// 同类商品 和 同大类商品
$sameCategoryProducts = Product::find()->where(['category_id' => $model->category_id])->orderBy(['sales' => SORT_DESC])->limit(3)->all();
$sameRootCategoryProducts = Product::find()->where(['category_id' => $arraySameRootCategory])->orderBy(['sales' => SORT_DESC])->limit(Yii::$app->params['productHotCount'])->all();
// 记录浏览日志
$historyProducts = [];
$cookies = Yii::$app->request->cookies;
if ($cookies->has('productHistory')) {
$arrHistory = explode(',', $cookies->getValue('productHistory'));
foreach ($arrHistory as $id) {
$product = Product::findOne($id);
if ($product) {
array_push($historyProducts, $product);
}
}
array_unshift($arrHistory, $id);
$arrHistory = array_unique($arrHistory);
while (count($arrHistory) > Yii::$app->params['productHistoryCount']) {
array_pop($arrHistory);
}
Yii::$app->response->cookies->remove('productHistory');
Yii::$app->response->cookies->add(new Cookie(['name' => 'productHistory', 'value' => implode(',', $arrHistory), 'expire' => time() + 3600 * 24 * 30]));
} else {
Yii::$app->response->cookies->add(new Cookie(['name' => 'productHistory', 'value' => $id, 'expire' => time() + 3600 * 24 * 30]));
}
return $this->render('view', ['model' => $model, 'allCategory' => $allCategory, 'arrayCategoryIdName' => $arrayCategoryIdName, 'sameCategoryProducts' => $sameCategoryProducts, 'sameRootCategoryProducts' => $sameRootCategoryProducts, 'historyProducts' => $historyProducts]);
}
示例10: getProductByCategory
public static function getProductByCategory($category_id, $limit = 6)
{
$category = new Category();
$product = new Product();
$categoriesData = $category->findAll(['parent_id' => $category_id]);
$categoryIDs = [];
if ($categoriesData) {
foreach ($categoriesData as $categoryData) {
$categoryIDs[] = $categoryData->id;
}
$products = $product->find()->where(['status' => 10, 'is_featured' => 10])->andWhere(['in', 'category_id', $categoryIDs])->limit($limit)->all();
} else {
$products = $product->find()->where(['status' => 10, 'is_front' => 10, 'category_id' => $category_id])->limit($limit)->all();
}
return $products;
}
示例11: search
public function search($params)
{
$query = Category::find()->where(['status' => Category::STATUS_DISPLAY]);
$dataProvider = new ActiveDataProvider(['query' => $query]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
if ($this->name) {
$query->andFilterWhere(['like', 'name', $this->name]);
}
if ($this->slug) {
$query->andFilterWhere(['like', 'slug', $this->slug]);
}
if ($this->parent) {
$category = Category::find()->where(['like', 'name', $this->parent])->all();
if ($category) {
$c_ids = [];
foreach ($category as $v) {
$c_ids[] = $v->id;
}
$query->andFilterWhere(['in', 'parent', $c_ids]);
} else {
$query->andFilterWhere(['in', 'id', [0]]);
}
}
return $dataProvider;
}
示例12: findById
protected function findById($id)
{
if (($model = Category::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('请求页面不存在');
}
}
示例13: findModel
/**
* Finds the Category model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $id
* @return Category the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Category::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例14: getCategoryList
/**
* Возвращает список возможных категорий товара.
* Примечание: используется в backend/user/index представлении.
*
* @return mixed
*/
public static function getCategoryList()
{
$categories = [];
foreach (Category::getCategory() as $item_name) {
$categories[$item_name->id] = $item_name->name;
}
return $categories;
}
示例15: actionIndex
public function actionIndex($c_url)
{
$model = Category::find()->with(['activeSubcategories'])->byUrl($c_url)->active()->one();
if ($model === null) {
throw new NotFoundHttpException();
}
return $this->render('index', ['model' => $model]);
}