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


PHP Categories::findOne方法代码示例

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


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

示例1: upload

 public function upload()
 {
     if ($this->validate()) {
         $cat = Categories::findOne($this->id);
         $contr = Yii::$app->controllerNamespace . '\\' . ucfirst($cat->handler) . 'Controller';
         $base = $contr::baseStorePath();
         $store_to = $base['real'] . $cat->route;
         foreach ($this->files as $f) {
             $new_fn = $this->newFileName($f->baseName, $f->extension);
             if ($f->saveAs($store_to . $new_fn)) {
                 $res = new Resources();
                 $res->attachBehavior('ImageBehavior', ['class' => ImageBehavior::className()]);
                 $res->category_id = $this->id;
                 $res->title = $res->description = $f->baseName;
                 $res->keywords = $new_fn;
                 //реальное имя файла с расширением
                 $res->alias = str_replace('.' . $f->extension, '', $new_fn);
                 //псевдоним изначально равен имени файла
                 $res->path = $store_to;
                 $res->webroute = $base['web'] . $cat->route;
                 $res->filename = $new_fn;
                 $res->save();
             }
             //TODO обработка ошибки сохранения файла
         }
         return true;
     }
     return false;
 }
开发者ID:kintastish,项目名称:mobil_old,代码行数:29,代码来源:FileUploadModel.php

示例2: findModel

 protected function findModel($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:kintastish,项目名称:mobil,代码行数:8,代码来源:CatController.php

示例3: actionIndexbycategory

 /**
  * Lists all Apis models that fit in a Category.
  * @param integer $categoryId
  * @return mixed
  */
 public function actionIndexbycategory($categoryId)
 {
     $searchModel = new ApisSearch();
     $queryParams = array_merge(['ApisSearch' => ['cbs' => 0, 'category' => $categoryId]], Yii::$app->request->getQueryParams());
     $dataProvider = $searchModel->search($queryParams);
     $category = Categories::findOne($categoryId);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'category' => $category]);
 }
开发者ID:openi-ict,项目名称:api-builder,代码行数:13,代码来源:ApisController.php

示例4: getCategoryID

 public static function getCategoryID($category)
 {
     if (is_null(\app\models\Categories::findOne(['category' => $category]))) {
         return null;
     } else {
         return \app\models\Categories::findOne(['category' => $category])->id;
     }
 }
开发者ID:noldsel,项目名称:webdev-challenge,代码行数:8,代码来源:Categories.php

示例5: loadModel

 /**
  * Загружает запись модели текущего контроллера по айдишнику
  * @param $id
  * @return null|static
  * @throws \yii\web\HttpException
  */
 public function loadModel($id)
 {
     $model = Categories::findOne($id);
     if ($model === null) {
         throw new \yii\web\HttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
开发者ID:roman1970,项目名称:lis,代码行数:14,代码来源:CategoriesController.php

示例6: actionViewall

 public function actionViewall($cid = 2)
 {
     $query = Article::find()->where(['cid' => $cid, 'published' => 1]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->orderBy('ordering')->all();
     $cat = \app\models\Categories::findOne($cid);
     return $this->render('viewall', ['model' => $models, 'cat' => $cat, 'pages' => $pages]);
 }
开发者ID:jatuponp,项目名称:discovery,代码行数:9,代码来源:SiteController.php

示例7: actionCategory

 public function actionCategory($id)
 {
     $model = Categories::findOne($id);
     $category = $model->find()->where(['id' => $id])->one();
     $news = new News();
     $data = $news->fromCategory($id, 20, $this->paging(20));
     $datat1 = $news->fromCategory($id, 5, 0);
     $datat2 = $news->fromCategory($id, 4, 5);
     return $this->render('itemcategory', ['data' => $data, 'datat1' => $datat1, 'datat2' => $datat2, 'category' => $category, 'model' => $model]);
 }
开发者ID:lyhoi2204,项目名称:yii2,代码行数:10,代码来源:SiteController.php

示例8: getHierarchy

 public static function getHierarchy($id)
 {
     $cat = Categories::findOne($id);
     $hier = [];
     while ($cat !== null) {
         $hier[] = $cat;
         $cat = Categories::findOne($cat->parent_id);
     }
     return $hier;
 }
开发者ID:kintastish,项目名称:mobil,代码行数:10,代码来源:Categories.php

示例9: actionList

 public function actionList($id)
 {
     if ($id == 0) {
         throw new \yii\web\BadRequestHttpException("Неправильный запрос");
     }
     $q = Resources::find()->where(['category_id' => $id]);
     $dataProvider = new ActiveDataProvider(['query' => $q]);
     $uploadModel = new FileUploadModel();
     $uploadModel->id = $id;
     return $this->render('list', ['dataProvider' => $dataProvider, 'album' => Categories::findOne($id), 'uploadModel' => $uploadModel]);
 }
开发者ID:kintastish,项目名称:mobil_old,代码行数:11,代码来源:ImageController.php

示例10: actionList

 /**
  ** Вывод списка страниц. Если задан $id категории - списка страниц категории
  */
 public function actionList($id = 0)
 {
     $q = Resources::find();
     if ($id > 0) {
         $q->where(['category_id' => $id]);
     } else {
         $q->joinWith('category')->where(['categories.handler' => $this->id]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $q, 'pagination' => false]);
     return $this->render('list', ['category' => Categories::findOne($id), 'dataProvider' => $dataProvider, 'category_id' => $id]);
 }
开发者ID:kintastish,项目名称:mobil_old,代码行数:14,代码来源:PageController.php

示例11: getStoreInfo

 private function getStoreInfo()
 {
     $path = [];
     switch ($this->tableId) {
         case Resources::$tableId:
             $model = Resources::findOne($this->id);
             $handler = $model->category->handler;
             $route = $model->route;
             break;
         case Categories::$tableId:
             $model = Categories::findOne($this->id);
             $handler = $model->handler;
             $route = $model->route;
             break;
         default:
             throw new InvalidConfigException('FileUploadModel - неизвестный ID таблицы');
             break;
     }
     $contrClass = Yii::$app->controllerNamespace . '\\' . ucfirst($handler) . 'Controller';
     $path = $contrClass::baseStorePath();
     $path['route'] = $route;
     return $path;
 }
开发者ID:kintastish,项目名称:mobil,代码行数:23,代码来源:FileUploadModel.php

示例12: actionUpdate

 public function actionUpdate($id = null)
 {
     $model = new Categories();
     if ($model->load($_POST)) {
         $id = $_POST['Categories']['id'];
         if ($id) {
             $model = Categories::findOne($id);
             $model->attributes = $_POST['Categories'];
         }
         if ($model->save()) {
             return $this->redirect(['index', 'langs' => $_POST['Categories']['langs']]);
         } else {
             print_r($model->getErrors());
             exit;
         }
     }
     if ($id) {
         $model = Categories::findOne($id);
     } else {
         $model->langs = $_REQUEST['langs'];
     }
     return $this->render('update', ['model' => $model]);
 }
开发者ID:jatuponp,项目名称:iweb,代码行数:23,代码来源:CategoriesController.php

示例13: actionUpdate

 public function actionUpdate($id = null)
 {
     $model = new Categories();
     if ($model->load(Yii::$app->request->post())) {
         $request = Yii::$app->request->post('Categories');
         $id = $request['id'];
         if ($id) {
             $model = Categories::findOne($id);
             $model->attributes = $request;
         }
         if ($model->save()) {
             return $this->redirect(['index', 'langs' => $request['langs']]);
         } else {
             print_r($model->getErrors());
             exit;
         }
     }
     if ($id) {
         $model = Categories::findOne($id);
     } else {
         $model->langs = Yii::$app->getRequest()->getQueryParam('langs', 'thai');
     }
     return $this->render('update', ['model' => $model]);
 }
开发者ID:jatuponp,项目名称:discovery,代码行数:24,代码来源:CategoriesController.php

示例14: actionDoneDeal

 /**
  * Сделал дело
  * @return string
  */
 public function actionDoneDeal()
 {
     if (Yii::$app->getRequest()->getQueryParam('user')) {
         $start_day = strtotime('now 00:00:00', time() + 7 * 60 * 60);
         $user = MarkUser::findOne(Yii::$app->getRequest()->getQueryParam('user'));
         if (Yii::$app->getRequest()->getQueryParam('deal')) {
             try {
                 $deal = DiaryDeals::find()->where("name like '" . trim(Yii::$app->getRequest()->getQueryParam('deal')) . "'")->one();
             } catch (\ErrorException $e) {
                 $deal = [];
             }
             if (!$deal) {
                 return 'Ошибка!';
             }
             //return var_dump($deal);
             $act = new DiaryActs();
             $act->model_id = 5;
             $act->user_id = $user->id;
             $act->mark = $deal->mark;
             $act->mark_status = 0;
             //return var_dump($act);
             if ($act->save(false)) {
                 $done_deal = new DiaryDoneDeal();
                 $done_deal->deal_id = $deal->id;
                 $done_deal->act_id = $act->id;
                 $done_deal->user_id = $user->id;
                 //return var_dump($done_deal);
                 if ($done_deal->save()) {
                     $today_acts = implode(',', ArrayHelper::map(DiaryActs::find()->where("time > {$start_day} and user_id = " . $user->id)->all(), 'id', 'id'));
                     $deals = [];
                     $sum_mark = 0;
                     $deal_cats = [];
                     $cat_deal = [];
                     if ($today_acts) {
                         $today_deals = DiaryDoneDeal::find()->where("act_id IN (" . $today_acts . ")")->all();
                         $sum_mark = DiaryActs::find()->select('SUM(mark)')->where("time > {$start_day} and user_id = " . $user->id)->scalar();
                         $mark_accumul = DiaryActs::find()->select('SUM(mark)')->where("time > " . mktime(0, 0, 0, 9, 1, 2016) . " and user_id = " . $user->id)->scalar();
                         $users_money = MarkUser::findOne(11)->money;
                         $money = $mark_accumul + $users_money;
                         foreach ($today_deals as $done_deal) {
                             $deals[] = DiaryDeals::findOne($done_deal->deal_id);
                             $deal_cats[Categories::findOne($done_deal->deal->cat_id)->name][] = DiaryDeals::findOne($done_deal->deal_id)->mark;
                             //return var_dump($done_deal->deal->cat_id);
                         }
                         foreach ($deal_cats as $cat => $marks) {
                             $mark = 0;
                             foreach ($marks as $mrk) {
                                 $mark += $mrk;
                             }
                             $cat_deal[$cat][] = $mark;
                         }
                     }
                     $all_deals = DiaryDeals::find()->all();
                     //return var_dump($deals);
                     return $this->renderPartial('deals', ['deal_cats' => $cat_deal, 'sum_mark' => $sum_mark, 'user' => $user, 'money' => $money]);
                 }
                 return $this->renderPartial('error');
             }
         }
     }
 }
开发者ID:roman1970,项目名称:lis,代码行数:65,代码来源:DefaultController.php

示例15: actionPosts

 /**
  * Отображает новости
  * @return string
  * @throws HttpException
  */
 public function actionPosts($category_url = null)
 {
     $this->layout = 'main';
     $query = Posts::find()->where(['active' => 1]);
     if ($category_url) {
         $category = Categories::findOne(['active' => 1, 'url' => $category_url]);
         if (!$category) {
             throw new HttpException(404, 'Категория не существует.');
         }
         $query = $query->andWhere(['category_id' => $category->id]);
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 5, 'pageParam' => 'pageNum', 'forcePageParam' => false, 'pageSizeParam' => false]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('posts', ['posts' => $models, 'pages' => $pages]);
 }
开发者ID:hysdop,项目名称:YobaCMS,代码行数:21,代码来源:PostsController.php


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