本文整理汇总了PHP中app\models\Categories::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Categories::find方法的具体用法?PHP Categories::find怎么用?PHP Categories::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Categories
的用法示例。
在下文中一共展示了Categories::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionShow
/**
* Показывает контент
* @return string
* @TODO Нужно предусмотреть возможность вывода разного контента, привязаного к одной категории
*
*/
public function actionShow()
{
$this->cat_id = Yii::$app->getRequest()->getQueryParam('id') ? Yii::$app->getRequest()->getQueryParam('id') : null;
$cat_obg = Categories::find()->where('id = ' . $this->cat_id)->one();
$allContent = Articles::find()->where('cat_id = ' . $this->cat_id)->all();
$allArticlesForPager = Articles::find()->where(['cat_id' => $this->cat_id]);
$countQueryCont = clone $allArticlesForPager;
$pagesGlobal = new Pagination(['totalCount' => $countQueryCont->count(), 'pageSize' => 1, 'forcePageParam' => false, 'pageSizeParam' => false]);
$artPages = $allArticlesForPager->offset($pagesGlobal->offset)->limit($pagesGlobal->limit)->all();
foreach ($allContent as $article) {
//var_dump($this->cat_id);
$this->article_id = $article->id;
$article = Articles::findOne($this->article_id);
$allArticles = ArticlesContent::find()->where(['articles_id' => $this->article_id])->orderBy(['id' => SORT_DESC]);
//var_dump($allArticles); exit;
$countQuery = clone $allArticles;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]);
$models = $allArticles->offset($pages->offset)->limit($pages->limit)->all();
$this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title;
$this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name;
$this->articles[] = ['article' => $article, 'contents' => $models, 'pages' => $pages, 'source' => $this->source, 'author' => $this->author];
}
//var_dump($this->articles); exit;
return $this->renderPartial($cat_obg->action, ['articles' => $this->articles, 'cat' => $this->cat_id, 'pagesGlobal' => $pagesGlobal, 'artPages' => $artPages, 'cat_obg' => $cat_obg]);
}
示例2: postForm
public function postForm(FormCategoryRequest $request)
{
if (!empty($request)) {
$pathImage = $request->get('picture', null);
$data = $request->all();
if ($request->hasfile('picture')) {
$validator = Validator::make($request->all(), ['picture' => ['mimes:jpg,png,jpeg']]);
if ($validator->fails()) {
return redirect(action('Admin\\CategoryController@postForm'))->withErrors($validator)->withInput();
}
$file = $request->file('picture');
$nameimage = date('Ymdhis') . rand(1, 1000) . '.' . $file->getClientOriginalExtension();
$file->move(public_path() . "/dinamic/category/", $nameimage);
$pathImage = '/dinamic/category/' . $nameimage;
$data['picture'] = $pathImage;
}
$data['flagactive'] = $request->get('flagactive', 1);
if ($request->id) {
$obj = Categories::find($request->id);
$obj->update($data);
$idTips = $obj->id;
} else {
$obj = Categories::create($data);
$idTips = $obj->id;
}
return redirect('admpanel/' . self::NAMEC)->with('messageSuccess', 'Caracteristicas Guardado');
}
return redirect('admpanel')->with('messageError', 'Error al guardar el tip');
}
示例3: actionIndex
/**
* Lists all Categories models.
* @return mixed
*/
public function actionIndex()
{
if (\Yii::$app->user->isGuest) {
return $this->goHome();
}
$dataProvider = new ActiveDataProvider(['query' => Categories::find()]);
return $this->render('index', ['dataProvider' => $dataProvider]);
}
示例4: actionList
public function actionList($id = 0)
{
if ($id != 0) {
return $this->redirect(['album/list', 'id' => $id]);
}
$q = Categories::find()->where(['handler' => $this->id]);
$dataProvider = new ActiveDataProvider(['query' => $q]);
return $this->render('list', ['dataProvider' => $dataProvider]);
}
示例5: actionKlavarosCats
public function actionKlavarosCats()
{
$res = [];
$m = Categories::find()->where(['site_id' => 13])->all();
foreach ($m as $h) {
$res[] = $h->name;
}
return json_encode($res);
}
示例6: actionDelete
/**
* Удаляет категорию
* @param $id
* @return \yii\web\Response
* @throws \yii\web\HttpException
*/
public function actionDelete($id)
{
if ($model = $this->loadModel($id)->delete()) {
$cats = Categories::find()->all();
return $this->render(['index', ['cats' => $cats]]);
} else {
throw new \yii\web\HttpException(404, 'Cant delete record.');
}
}
示例7: actionUpdate
/**
* Updates an existing Categories model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $categoryId
* @return mixed
*/
public function actionUpdate($categoryId)
{
$categories = Categories::find()->all();
//findAllExceptOne($categoryId);
$model = $this->findModel($categoryId);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'categoryId' => $model->category_id]);
} else {
return $this->render('update', ['model' => $model, 'categories' => $categories]);
}
}
示例8: actionUpdate
/**
* Updates an existing Product model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $itemId
* @return mixed
*/
public function actionUpdate($itemId)
{
$categories = Categories::find()->all();
// need this for dropDownList in views/product/_form.php
$model = $this->findModel($itemId);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'itemId' => $model->item_id]);
} else {
return $this->render('update', ['model' => $model, 'categories' => $categories]);
}
}
示例9: actionList
public function actionList($categoryId = null)
{
/** @var Category $category */
$category = null;
$categories = Categories::find()->indexBy('category_id')->orderBy('category_id')->all();
$productsQuery = Product::find();
if ($categoryId !== null && isset($categories[$categoryId])) {
$category = $categories[$categoryId];
$productsQuery->where(['category_id' => $this->getCategoryIds($categories, $categoryId)]);
}
$productsDataProvider = new ActiveDataProvider(['query' => $productsQuery, 'pagination' => ['pageSize' => 10]]);
return $this->render('list', ['category' => $category, 'menuItems' => $this->getMenuItems($categories, isset($category->category_id) ? $category->category_id : null), 'productsDataProvider' => $productsDataProvider]);
}
示例10: remove
public function remove($category_id)
{
$category = Categories::find($category_id);
$category->delete();
if (Input::get('with_posts', '0') == '1') {
Posts::where('category_id', $category_id)->delete();
Notifications::add('Category removed with posts', 'success');
} else {
Posts::where('category_id', $category_id)->update(['category_id' => '1']);
Notifications::add('Category removed. Posts moved to Uncategorized', 'success');
}
return Redirect::route('root-categories');
}
示例11: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Categories::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['category_id' => $this->category_id, 'parent_category_id' => $this->parent_category_id, 'date_added' => $this->date_added, 'date_modified' => $this->date_modified, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
$query->andFilterWhere(['like', 'category_name', $this->category_name]);
return $dataProvider;
}
示例12: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Categories::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'created_by' => $this->created_by, 'created_at' => $this->created_at]);
$query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
return $dataProvider;
}
示例13: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Categories::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->joinWith('idArea');
$query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'service_level_agreement_asignment' => $this->service_level_agreement_asignment, 'service_level_agreement_completion' => $this->service_level_agreement_completion]);
$query->andFilterWhere(['like', 'categories.name', $this->name])->andFilterWhere(['like', 'categories.description', $this->description])->andFilterWhere(['like', 'areas.name', $this->id_area]);
return $dataProvider;
}
示例14: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Categories::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere(['id' => $this->id, 'lft' => $this->lft, 'rgt' => $this->rgt, 'depth' => $this->depth, 'tree' => $this->tree]);
$query->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
示例15: actionIndex
/**
* @return string
*/
public function actionIndex()
{
$uploadFile = new UploadForm();
//var_dump($_POST);
if (Yii::$app->request->isPost) {
$uploadFile->file = UploadedFile::getInstance($uploadFile, 'file');
// var_dump($uploadFile->file); exit;
if ($uploadFile->file && $uploadFile->validate()) {
$uploadFile->file->saveAs('uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension);
} else {
print_r($uploadFile->getErrors());
exit;
}
}
$cats = Categories::find()->where('site_id =' . $this->site->id)->roots()->all();
$articles = Articles::find()->where('site_id =' . $this->site->id . ' or site_id = 13')->all();
//$cats = Categories::find()->leaves()->all();
return $this->render('index', ['cats' => $cats, 'articles' => $articles, 'uploadFile' => $uploadFile]);
}