本文整理汇总了PHP中app\models\Category::getCategoryById方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::getCategoryById方法的具体用法?PHP Category::getCategoryById怎么用?PHP Category::getCategoryById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::getCategoryById方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTopicOptions
/**
* @return array
*/
public function getTopicOptions()
{
$raw = Topic::find()->orderBy('Category_id')->all();
$arr = array();
foreach ($raw as $row) {
$categpry = \app\models\Category::getCategoryById($row['Category_id']);
$arr[$row['id']] = $categpry . ' - ' . $row['name'];
}
return $arr;
}
示例2: export
public function export()
{
$data = array(array('Name', 'Alias', 'Meta keywords', 'Meta description', 'Parent', 'Publish', 'Views', 'Type'));
$pages = Category::getCategoriesByContentType(2);
foreach ($pages as $page) {
$page_array = array();
$name = $page['name'];
array_push($page_array, $name);
$alias = $page['alias'];
array_push($page_array, $alias);
if (empty($page['meta_keys'])) {
$meta_keys = 'None';
} else {
$meta_keys = $page['meta_keys'];
}
array_push($page_array, $meta_keys);
if (empty($page['meta_desc'])) {
$meta_desc = 'None';
} else {
$meta_desc = $page['meta_desc'];
}
array_push($page_array, $meta_desc);
if ($page['type'] == 1) {
$parent = 'None';
} else {
$parent = Category::getCategoryById($page['parent_id'])['name'];
}
array_push($page_array, $parent);
if ($page['publish'] == 1) {
$publish = 'Published';
} else {
$publish = 'Unpublished';
}
array_push($page_array, $publish);
$views = (string) $page->visits()->count();
array_push($page_array, $views);
if ($page['type'] == 1) {
$type = 'Parent';
} else {
$type = 'Sub category';
}
array_push($page_array, $type);
array_push($data, $page_array);
}
Excel::create('Pages', function ($excel) use($data) {
$excel->sheet('Pages', function ($sheet) use($data) {
$sheet->fromArray($data, null, 'A1', false, false);
$sheet->cells('A1:H1', function ($cells) {
$cells->setFontWeight('bold');
});
});
})->export('xls');
}
示例3: export
/**
* Export posts
*/
public function export()
{
$data = array(array('Name', 'Alias', 'Tags', 'Category', 'Status', 'Views', 'Publish'));
$posts = Post::getPosts(0, '', Auth::user()->id);
foreach ($posts as $post) {
$post_array = array();
$alias = $post['alias'];
array_push($post_array, $alias);
if ($post->tags->count() == 0) {
$tags = 'None';
} else {
$tags = "";
foreach ($post->tags as $tag) {
$tags .= $tag['name'] . ',';
}
}
array_push($post_array, $tags);
if (empty($post['category_id'])) {
$category = 'None';
} else {
$category = Category::getCategoryById($post['category_id'])['name'];
}
array_push($post_array, $category);
if ($post['approve'] == 1) {
$status = 'Approved';
} else {
$status = 'Not approved';
}
array_push($post_array, $status);
$visits = (string) $post->visits()->count();
array_push($post_array, $visits);
if (empty($post['publish'])) {
$publish = 'Unpublished';
} else {
$publish = 'Published';
}
array_push($post_array, $publish);
array_push($data, $post_array);
}
Excel::create('Posts', function ($excel) use($data) {
$excel->sheet('Posts', function ($sheet) use($data) {
$sheet->fromArray($data, null, 'A1', false, false);
$sheet->cells('A1:G1', function ($cells) {
$cells->setFontWeight('bold');
});
});
})->export('xls');
}