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


PHP Category::findOne方法代码示例

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


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

示例1: actionEdit

 public function actionEdit($id)
 {
     $categoryModel = Category::findOne(['id' => $id]);
     if ($categoryModel->load(Yii::$app->request->post()) && $categoryModel->save()) {
     }
     return $this->render('edit', ['model' => $categoryModel]);
 }
开发者ID:stanislavdev1993,项目名称:blog,代码行数:7,代码来源:CategoryController.php

示例2: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $this->scenario = '';
     $query = Product::find()->where(['active' => 1]);
     $this->scenario = 'default';
     $this->load($params, '');
     $order_arr = !empty($this->order_by) ? explode(':', $this->order_by) : ['id', 'desc'];
     $orderField = count($order_arr) > 0 ? $order_arr[0] : 'id';
     $orderSort = count($order_arr) > 1 && $order_arr[1] == 'desc' ? SORT_DESC : SORT_ASC;
     $this->order_by = $orderField . ':' . ($orderSort == SORT_DESC ? 'desc' : 'asc');
     /** @var Category $category */
     if (isset($params['code']) && !empty($params['code'])) {
         $this->_category = Category::find()->where(['url_code' => $params['code']])->one();
     }
     if (is_null($this->_category) && isset($params['id']) && !empty($params['id'])) {
         $this->_category = Category::findOne($params['id']);
     }
     if (!is_null($this->_category)) {
         $arr_cats = $this->_category->fillSubCategoryArray();
         $query->andFilterWhere(['in', 'category_id', $arr_cats]);
     }
     $per_page = isset($params['per-page']) ? $params['per-page'] : 12;
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $per_page], 'sort' => ['defaultOrder' => ['new' => SORT_DESC], 'attributes' => ['new' => ['desc' => ['id' => SORT_DESC], 'asc' => false, 'default' => SORT_DESC, 'label' => Yii::t('app', 'Newest Arrivals')], 'featured' => ['asc' => false, 'desc' => ['featured' => SORT_DESC], 'default' => SORT_DESC, 'label' => Yii::t('app', 'Featured')], 'price_asc' => ['desc' => false, 'asc' => ['price_custom' => SORT_ASC], 'default' => SORT_ASC, 'label' => Yii::t('app', 'Price: Low to High')], 'price_desc' => ['asc' => false, 'desc' => ['price_custom' => SORT_DESC], 'default' => SORT_DESC, 'label' => Yii::t('app', 'Price: High to Low')]]]]);
     return $dataProvider;
 }
开发者ID:rcjusto,项目名称:simplestore,代码行数:32,代码来源:ItemCategorySearch.php

示例3: findModelByAlias

 /**
  * 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 $alias
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelByAlias($alias)
 {
     if (($model = Category::findOne(['alias' => $alias])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:heartshare,项目名称:yii2-crazydb-blog,代码行数:15,代码来源:CategoryController.php

示例4: 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:janusnic,项目名称:yii-blog,代码行数:14,代码来源:Category.php

示例5: findModel

 /**
  * @param string $id
  * @return Category|bool
  * @throws NotFoundHttpException
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         return false;
     }
 }
开发者ID:amarchenkov,项目名称:myCMS,代码行数:13,代码来源:CategoryUrlRule.php

示例6: findModel

 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null && $model->user_id == Yii::$app->user->id) {
         return $model;
     } else {
         throw new NotFoundHttpException('The page you requested is not available or does not exist.');
     }
 }
开发者ID:BakhtiyorRuziev,项目名称:economizzer,代码行数:8,代码来源:CategoryController.php

示例7: findModel

 /**
  * Finds the Users model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Users 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:artoodetoo,项目名称:BlogMVC,代码行数:15,代码来源:CategoryController.php

示例8: getParentName

 /**
  * @return \yii\db\ActiveQuery
  */
 public function getParentName()
 {
     if ($this->parent != 0) {
         $data = Category::findOne($this->parent);
         return Html::a($data->name, ['view', 'id' => $data->id]);
     } else {
         return "Главная категория";
     }
 }
开发者ID:dosh93,项目名称:shop,代码行数:12,代码来源:Category.php

示例9: actionList

 /**
  * @param $node
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionList($node)
 {
     $category = Category::findOne($node);
     if (!$category) {
         throw new NotFoundHttpException();
     }
     $model = new ProductSearch();
     $dataProvider = $model->search(\Yii::$app->request->queryParams);
     return $this->render('list', ['dataProvider' => $dataProvider, 'searchModel' => $model, 'category' => $category]);
 }
开发者ID:vetoni,项目名称:toko,代码行数:15,代码来源:ProductController.php

示例10: actionCategory

 public function actionCategory($categories = null)
 {
     if ($categories) {
         $category = Category::findOne(['categories' => $categories]);
         if ($category) {
             return $this->render('category', ['model' => $category]);
         }
     } else {
         $this->goHome();
     }
 }
开发者ID:Ramengel,项目名称:yii_fl,代码行数:11,代码来源:MainController.php

示例11: loadCategory

 static function loadCategory()
 {
     $categories = \app\models\Category::find()->asArray()->all();
     for ($i = 0; $i <= count($categories) - 1; $i++) {
         if ($categories[$i]['parent'] != 0) {
             $categories[$i]['name'] = $categories[$i]['name'] . "(" . \app\models\Category::findOne(['id' => $categories[$i]['parent']])->name . ")";
         }
     }
     $categories = ArrayHelper::map($categories, 'id', 'name');
     return $categories;
 }
开发者ID:dosh93,项目名称:shop,代码行数:11,代码来源:Product.php

示例12: actionFixCategory

 public function actionFixCategory()
 {
     $catGoogle = \app\models\CategoryGoogle::find()->all();
     foreach ($catGoogle as $cat) {
         if (isset($cat->parent_id)) {
             $mCat = \app\models\Category::findOne($cat->parent_id);
             $mGoogleCat = \app\models\CategoryGoogle::findOne(['nombre' => $mCat->nombre_categoria]);
             $cat->parent_id = $mGoogleCat->id;
             $cat->save();
         }
     }
 }
开发者ID:pachopascolat,项目名称:turismoYii,代码行数:12,代码来源:PlaceController.php

示例13: init

 public function init()
 {
     parent::init();
     $category = Category::findOne(83);
     $descendants = $category->children()->all();
     $menuItems = [];
     foreach ($descendants as $key => $value) {
         $menuItems[] = ['label' => $value->name, 'url' => ['post/index', 'id' => $value->id]];
     }
     $menuItems[] = ['label' => '未分类', 'url' => ['post/index', 'id' => 0]];
     echo '<h4 class="text-right">分类</h4>';
     echo Menu::widget(['options' => ['class' => 'side-menu list-unstyled'], 'items' => $menuItems, 'encodeLabels' => false]);
 }
开发者ID:rocketyang,项目名称:dcms2,代码行数:13,代码来源:CategoryWidget.php

示例14: actionIndex

 public function actionIndex()
 {
     $queryParams = Yii::$app->request->getQueryParams();
     $query = Post::find()->where(['status' => 1]);
     $category = "";
     if (isset($queryParams['id'])) {
         $category = Category::findOne($queryParams['id']);
         $query = $query->andWhere(['category_id' => $queryParams['id']]);
     }
     if (isset($queryParams['tag'])) {
         $query = $query->andWhere(['like', 'tags', $queryParams['tag']]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]], 'pagination' => ['pageSize' => 20]]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'category' => $category]);
 }
开发者ID:rocketyang,项目名称:dcms2,代码行数:15,代码来源:PostController.php

示例15: actionCategory

 public function actionCategory($id)
 {
     $cur_category = Category::findOne($id);
     if ($cur_category === null) {
         throw new NotFoundHttpException();
     } elseif ($cur_category->status === Category::STATUS_INACTIVE) {
         return $this->redirect(['index']);
     }
     $categories = Category::find()->where(['status' => Category::STATUS_ACTIVE])->orderBy('caption')->all();
     $query = $cur_category->getNews()->where(['status' => News::STATUS_ACTIVE])->orderBy('date DESC');
     $count = $query->count();
     $pagination = new Pagination(['totalCount' => $count, 'defaultPageSize' => NewsController::DEFAULT_PAGE_SIZE]);
     $news = $query->offset($pagination->offset)->orderBy('date')->limit($pagination->limit)->all();
     return $this->render('index', ['categories' => $categories, 'news' => $news, 'pagination' => $pagination, 'cur_category' => $cur_category]);
 }
开发者ID:Everus,项目名称:idflyTest,代码行数:15,代码来源:SiteController.php


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