本文整理汇总了PHP中app\models\Category::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::find方法的具体用法?PHP Category::find怎么用?PHP Category::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getById
/**
* Get by category id.
*
* @param $id
*/
public function getById($id)
{
$category = $this->model->find($id);
if (!is_null($category)) {
$category->hot++;
$category->update();
}
return $category;
}
示例2: deleteCategory
public function deleteCategory()
{
$id = \Input::all();
$category = Category::find($id['id']);
$retData = $category->delete() ? 200 : 500;
return \Response::json($retData);
}
示例3: index
public function index($categoryId)
{
$perPage = 2;
$articles = Category::find($categoryId)->article;
$maxPage = $articles->chunk($perPage)->count();
if (Request::has('page')) {
$articles = $articles->forPage(Request::get('page'), $perPage);
//dd($articles);
$firstArticle = $articles->shift();
$others = $articles;
return view('category')->with(['first' => $firstArticle, 'others' => $others, 'maxPage' => $maxPage]);
} else {
$articles = $articles->forPage(1, $perPage);
$firstArticle = $articles->shift();
$others = $articles;
return view('category')->with(['first' => $firstArticle, 'others' => $others, 'maxPage' => $maxPage]);
}
/*$article = Category::find($categoryId)->article;
$maxPage = intval(ceil(Article::count()/$perPage));
$firstArticle = $article->shift();
$others = $article;
return view('home')->with(['first' => $firstArticle, 'others' => $others, 'maxPage' => $maxPage]);*/
/*$categories = Category::all();
$articles = Article::paginate(15);
return view('home')->withArticles($articles)->withCategories($categories);*/
}
示例4: __construct
public function __construct(PostTypeRepositoryInterface $postTypeRepos, PostRepositoryInterface $postRepos, TemplateRepositoryInterface $templateRepos, PostService $postService)
{
$this->postTypeRepos = $postTypeRepos;
$this->postRepos = $postRepos;
$this->templateRepos = $templateRepos;
$this->postService = $postService;
$this->authUser = Auth::user();
if (!$this->authUser->is('superadmin')) {
App::abort(403, 'Access denied');
}
//get the post type from the url param
$routeParamters = Route::current()->parameters();
$postTypeId = $routeParamters['posttypeid'];
$this->postType = $this->postTypeRepos->find($postTypeId);
//get the categories, category check convert to route middleware
$categoryRootId = $this->postType->getConfiguredRootCategory();
if (!$categoryRootId) {
return Redirect::route('admin.post-types.configuration', [$postTypeId, "root"])->send();
}
$root = Category::find($categoryRootId);
if (!$root->descendants()->count()) {
return Redirect::route('admin.post-types.configuration', [$postTypeId, "descendants"])->send();
}
$categories = $root->descendants()->get();
foreach ($categories as $category) {
$this->categories[$category->id] = $category->title;
}
//localization
$this->locales = Locale::where('language', '!=', 'en')->lists('language', 'language');
$this->first_locale = array_first($this->locales, function () {
return true;
});
//share the post type submenu to the layout
View::share('postTypesSubmenu', $this->postTypeRepos->renderMenu());
}
示例5: actionIndex
/**
* Displays the index (home) page.
* Use it in case your home page contains static content.
*
* @return string
*/
public function actionIndex()
{
$searchModel = new ServiceSearch();
$searchModel->promo = true;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('tempindex', ['cat' => Category::find()->orderBy('name_pt')->all(), 'serv' => Service::find()->orderBy('title_pt')->all(), 'modelImg' => Campaign::find()->one(), 'dataProvider' => $dataProvider]);
}
示例6: getUpdate
public function getUpdate($id)
{
return view('category.form',[
'category' => Category::find($id),
'update' => 'обновить'
]);
}
示例7: edit
/**
* Edit page
*
* @param Request $request
* @param int $id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function edit(Request $request, $id = 0)
{
if ($request->isMethod('post')) {
$rules = ['name' => 'required|unique:categories,name,' . $id, 'alias' => 'required|unique:categories,alias,' . $id, 'content' => 'required'];
Validator::make($request->all(), $rules)->validate();
$page = Category::find($id);
$page->name = $request->input('name');
$page->alias = $request->input('alias');
$page->meta_keys = $request->input('meta_keys');
$page->meta_desc = $request->input('meta_desc');
if ($request->has('parent')) {
$page->parent_id = $request->input('parent');
$page->type = 2;
} else {
$page->type = 1;
}
$page->publish = $request->has('publish');
$page->save();
$page_content = $page->content;
$page_content->content = $request->input('content');
$page_content->save();
return redirect()->route('pages');
} else {
$page = Category::getCategoryById($id);
if (empty($page)) {
return redirect()->back();
} else {
$pages = Category::getParentCategories($id);
return view('admin.page.edit', compact('pages', 'page'));
}
}
}
示例8: postCategories
public function postCategories(Request $request)
{
if ($request->has('adds')) {
$adds = $request->adds;
for ($i = 0; $i < count($adds); $i++) {
if ($adds[$i]['parent_id'] == 'null') {
Category::create(['title' => $adds[$i]['title']]);
} else {
$parent = Category::find($adds[$i]['parent_id']);
$child = $parent->children()->create(['title' => $adds[$i]['title'], 'slug' => str_slug($adds[$i]['title'])]);
for ($j = 0; $j < count($adds); $j++) {
if ($adds[$j]['parent_id'] == $adds[$i]['id']) {
$adds[$j]['parent_id'] = $child->id;
}
}
}
}
}
if ($request->has('updates')) {
$updates = $request->updates;
for ($i = 0; $i < count($updates); $i++) {
$category = Category::find($updates[$i]['id']);
$category->update(['title' => $updates[$i]['title'], 'slug' => str_slug($updates[$i]['title'])]);
}
}
if ($request->has('deletes')) {
$deletes = $request->deletes;
for ($i = 0; $i < count($deletes); $i++) {
Category::destroy($deletes[$i]);
}
}
}
示例9: actionDrop
public function actionDrop()
{
$model = new SurveyResult();
$catList = ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'name');
$subcatList = ArrayHelper::map(Subcategory::find()->asArray()->all(), 'id', 'name');
return $this->render('drop', ['model' => $model, 'catList' => $catList, 'subcatList' => $subcatList]);
}
示例10: testUpdate
/**
* @depends testStore
*/
public function testUpdate($category)
{
$this->put(route('api.admin.category.item', $category), json_encode(['category_name' => 'test edited']));
$category = Category::find($category->id);
$this->assertEquals('test edited', $category->category_name);
$this->assertResponseOk();
}
示例11: actionIndex
/**
* Lists all Service models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ServiceSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$cat = Category::find()->orderBy('name_pt')->asArray()->all();
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'cat' => $cat]);
}
示例12: actionDelete
public function actionDelete($id)
{
$model = Category::find()->where(['id' => $id])->one();
$model->unlinkAll('posts', true);
Category::deleteAll(['id' => $id]);
return $this->actionNew();
}
示例13: actionIndex
public function actionIndex($mid = '', $f = 0)
{
$user = User::findIdentity(Yii::$app->user->id);
$regFrm = new RegisterForm();
$rstFrm = new RestorePswForm();
$spOffs = new SpecialOffer();
$spOffs = $spOffs->getAllSpecialOffers();
if ($f) {
$logFrm = new LoginForm(['scenario' => LoginForm::SCENARIO_LOGIN_CAPTCHA]);
} else {
$logFrm = new LoginForm(['scenario' => LoginForm::SCENARIO_LOGIN]);
}
$city = City::find()->all();
$address = new Address();
$distr = $address->getDistrict();
$category = Category::find()->all();
$brand = Brand::find()->all();
$msg = '';
switch ($mid) {
case 1:
$msg = Common::M_EMAIL_SEND;
break;
case 2:
$msg = Common::M_PSW_EMAIL_SEND;
break;
case 3:
$msg = Common::M_PSW_RESTORE_SUCCESS;
break;
}
return $this->render('index', ['msg' => $msg, 'user' => $user, 'spOffs' => $spOffs, 'regFrm' => $regFrm, 'logFrm' => $logFrm, 'rstFrm' => $rstFrm, 'city' => $city, 'distr' => $distr, 'category' => $category, 'brand' => $brand]);
}
示例14: save
public function save()
{
if (!$this->product_id) {
return Category::find($this->category)->product()->create($this->fields());
}
return DB::table('products')->where('id', $this->product_id)->update(['category_id' => $this->category, 'name' => $this->name, 'type' => $this->type, 'length' => $this->length, 'thickness' => $this->thickness, 'width' => $this->width, 'description' => $this->description, 'hidden' => $this->hidden]);
}
示例15: actionCategory
public function actionCategory($slug = '')
{
$query = Product::find();
$query->byCategorySlug($slug);
$dataProvider = new \yii\data\ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 4]]);
return $this->render('category', ['categoryModel' => Category::find()->bySlug($slug)->one(), 'dataProvider' => $dataProvider]);
}