本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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'));
}
示例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'));
}
示例6: findById
protected function findById($id)
{
if (($model = Category::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('请求页面不存在');
}
}
示例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.');
}
}
示例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.');
}
}
示例9: actionDelete
public function actionDelete()
{
/**
* @var $model Category
*/
$model = Category::findOne(Yii::$app->request->post('id'));
$model->delete();
}
示例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.'));
}
}
示例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]);
}
示例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;
}
示例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]);
}
示例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]);
}
示例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()]);
}