本文整理汇总了PHP中app\models\Category::roots方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::roots方法的具体用法?PHP Category::roots怎么用?PHP Category::roots使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::roots方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
$pid = intval(Input::get('id', 0));
if ($pid != 0) {
$category = Category::findOrFail($pid);
} else {
$category = false;
}
$roots = Category::roots()->get();
return view('admin.pages.category.add', compact('category', 'roots', 'pid'));
}
示例2: create
public function create($category = 0)
{
$category = intval($category);
if ($category > 0) {
$category = Category::findOrFail($category);
}
$categories = Category::roots()->get();
$user = Auth::user();
$states = Location::states()->first();
$regions = $states->children()->first();
$locations = $regions->children;
return view('pages.task.create', compact('category', 'categories', 'user', 'locations'));
}
示例3: getFilters
public function getFilters($slug)
{
$currentCat = Category::findBySlug($slug);
if (!$currentCat) {
$currentCat = Category::findBySlug("shop");
}
$filters = ["id" => $currentCat->id, "category" => "Categories", "child" => $currentCat->getDescendants(1, ['id', 'category'])->toHierarchy()];
$cats = Category::roots()->where("url_key", "!=", 'shop')->where("url_key", "!=", "popular")->get()->toHierarchy();
foreach ($cats as $cat) {
$cat->child = $cat->getDescendants(1, ['id', 'category'])->toHierarchy();
}
$cats = $cats->toArray();
array_unshift($cats, $filters);
return response()->json($cats);
}
示例4: getFill
public function getFill()
{
if (!$this->checkProfileType()) {
return redirect('/profile');
}
if ($this->checkProfileFill()) {
return redirect('/profile');
}
$user = $this->user;
$profile = $this->user->profile;
$city = $profile->city;
if ($city) {
$region = $city->parent;
} else {
$region = Location::states()->first()->children()->first();
}
$cities = $region->children;
$categories = Category::roots()->get();
$subscribePeriods = ['asap', 'hour', 'twice-day', 'day', 'two-days'];
return view('pages.profile.fill', compact('user', 'profile', 'cities', 'categories', 'subscribePeriods'));
}
示例5: subCategory
public function subCategory(Request $request, $category, $format = '')
{
if ($format == '' && $request->ajax()) {
$format = 'json';
}
$category = intval($category);
if ($category == 0) {
$categories = Category::roots()->get();
} else {
$category = Category::findOrFail($category);
$categories = $category->children;
}
$categoriesTranslated = [];
foreach ($categories as $c) {
$t = ['title' => trans('categories.' . $c['title'] . '.title'), 'url' => trans('categories.' . $c['title'] . '.url'), 'id' => $c->id, 'pid' => $c->pid];
$categoriesTranslated[] = $t;
}
if ($format = 'json') {
return $categoriesTranslated;
}
}
示例6: Category
<div class="category-index">
<h1><?php
echo Html::encode($this->title);
?>
</h1>
<p>
<?php
echo Html::a(Yii::t('app', 'Create Category'), ['create'], ['class' => 'btn btn-success']);
?>
</p>
<?php
$category = new Category();
$roots = $category->roots()->all();
foreach ($roots as $key => $root) {
$categories = Category::find()->where(['root' => $root->id])->orderBy('lft')->all();
$level = 0;
foreach ($categories as $n => $category) {
if ($category->level == $level) {
echo Html::endTag('li') . "\n";
} elseif ($category->level > $level) {
echo Html::beginTag('ul') . "\n";
} else {
echo Html::endTag('li') . "\n";
for ($i = $level - $category->level; $i; $i--) {
echo Html::endTag('ul') . "\n";
echo Html::endTag('li') . "\n";
}
}
示例7: Category
<?php
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\bootstrap\ActiveForm;
use app\models\Category;
/**
* @var yii\web\View $this
* @var app\models\Category $model
* @var yii\widgets\ActiveForm $form
*/
$category = new Category();
$Categories = $category->roots()->all();
$level = 0;
$items[0] = Yii::t('app', 'Please select the parent node');
foreach ($Categories as $key => $value) {
$items[$value->attributes['id']] = $value->attributes['name'];
$children = $value->descendants()->all();
foreach ($children as $child) {
$string = ' ';
$string .= str_repeat('│ ', $child->level - $level - 1);
if ($child->isLeaf() && !$child->next()->one()) {
$string .= '└';
} else {
$string .= '├';
}
$string .= '─' . $child->name;
$items[$child->id] = $string;
}
}
if (!$model->isNewRecord) {