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


PHP Category::findOne方法代码示例

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


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

示例1: testGetPostsWithCategory

 public function testGetPostsWithCategory()
 {
     $category = $this->categoryModel->findOne(1);
     $expectedPosts = $category->getPosts();
     $actualPosts = $this->postModel->findAll(['category_id' => 1, 'publish_status' => Post::STATUS_PUBLISH]);
     $this->assertEquals($expectedPosts->count, count($actualPosts));
 }
开发者ID:richardcj,项目名称:Blog-Yii2,代码行数:7,代码来源:CategoryTest.php

示例2: 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;
 }
开发者ID:wordnews,项目名称:wei_shop,代码行数:36,代码来源:Nav.php

示例3: 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;
 }
开发者ID:shunzi250,项目名称:xiaoego.com,代码行数:28,代码来源:StoreController.php

示例4: 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'));
 }
开发者ID:RubenDjOn,项目名称:originofthememes,代码行数:7,代码来源:CategoryController.php

示例5: 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'));
 }
开发者ID:czechcamus,项目名称:dasport,代码行数:7,代码来源:SiteController.php

示例6: findById

 protected function findById($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('请求页面不存在');
     }
 }
开发者ID:xiaomige,项目名称:giishop,代码行数:8,代码来源:CategoryServiceImpl.php

示例7: getCategory

 /**
  * Возвращает модель категории.
  * @param int $id идентификатор категории
  * @throws NotFoundHttpException в случае, когда категория не найдена
  * @return Category
  */
 public function getCategory($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested post does not exist.');
     }
 }
开发者ID:richardcj,项目名称:Blog-Yii2,代码行数:14,代码来源:Category.php

示例8: 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 integer $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.');
     }
 }
开发者ID:phpsong,项目名称:ExtJS5-Yii2,代码行数:15,代码来源:CategoryController.php

示例9: actionDelete

 public function actionDelete()
 {
     /**
      * @var $model Category
      */
     $model = Category::findOne(Yii::$app->request->post('id'));
     $model->delete();
 }
开发者ID:Mitonios,项目名称:mitonios-blog,代码行数:8,代码来源:CategoryController.php

示例10: findCategory

 /**
  * Finds the Category model based on its slug.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $slug
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findCategory($slug)
 {
     if (($model = Category::findOne(['slug' => $slug])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('frontend', 'The requested page does not exist.'));
     }
 }
开发者ID:cyanofresh,项目名称:yii2shop,代码行数:15,代码来源:CatalogController.php

示例11: actionView

 /**
  * Action method for viewing a single forum category.
  * @param integer $id of the forum category to be shown.
  * @param string|null $slug of the forum category to be shown. Default value is `null` meaning the requested topic
  * has no set slug.
  * @return string|Response action method execution result.
  * @throws HttpException in case category cannot be found.
  */
 public function actionView($id, $slug = null)
 {
     $category = Category::findOne($slug === null ? $id : ['id' => $id, 'slug' => $slug]);
     if ($category === null) {
         throw new HttpException(404, 'Cannot find requested forum category!');
     }
     return $this->render('view', ['category' => $category]);
 }
开发者ID:keltstr,项目名称:yii2-forum-1,代码行数:16,代码来源:CategoryController.php

示例12: getCategory

 public function getCategory()
 {
     $post = Post::findOne($this->id);
     foreach (explode(',', $post->category_id) as $value) {
         $category = Category::findOne($value);
         $data[] = ['id' => $category->id, 'parent_id' => $category->parent_id, 'title' => $category->title, 'indent' => $this->getIndent($category->indent)];
     }
     return $data;
 }
开发者ID:huynhtuvinh87,项目名称:cms,代码行数:9,代码来源:Post.php

示例13: actionCategory

 public function actionCategory($url)
 {
     $category = Category::findOne(['url' => $url]);
     if (empty($category)) {
         throw new BadRequestHttpException('Category Not Found!', 404);
     }
     $posts = Post::find()->where(['category_id' => $category['id']])->with('category')->all();
     return $this->render('list', ['posts' => $posts]);
 }
开发者ID:ninjacto,项目名称:ninjacto.com,代码行数:9,代码来源:BlogController.php

示例14: actionCategory

 public function actionCategory($id = null)
 {
     $category = Category::findOne(['id' => $id]);
     if ($category === NULL) {
         throw new NotFoundHttpException("Категория {$id} не найдена");
     }
     $this->getView()->title = "Mexanika 74 - Каталог техники: категория " . $category->name;
     return $this->render('category_item', ['category' => $category]);
 }
开发者ID:phpsong,项目名称:ExtJS5-Yii2,代码行数:9,代码来源:SiteController.php

示例15: actionRenderpage

 public function actionRenderpage($url)
 {
     $category = Category::findOne(['link' => $url]);
     if (empty($category)) {
         return $this->run('site/error');
     }
     $subcategories = Category::findAll(['parent' => $category->id]);
     $posts = Post::findAll(['category' => $category->id]);
     return $this->render('category', ['category' => $category, 'subcategories' => $subcategories, 'postsCount' => sizeof($posts), 'posts' => $posts, 'premiumPosts' => \common\models\Post::find()->where(['>', 'premium', date('d-m-Y H:i:s')])->andWhere(['category' => $category->id])->all()]);
 }
开发者ID:BoBRoID,项目名称:plochadka,代码行数:10,代码来源:SiteController.php


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