當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。