77 lines
2.1 KiB
PHP
77 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* 后台管理系统-首页
|
|
*/
|
|
namespace app\index\controller;
|
|
use app\index\controller\Base;
|
|
use think\facade\Db;
|
|
use think\facade\View;
|
|
use think\facade\Env;
|
|
use think\facade\Config;
|
|
|
|
class Index extends Base
|
|
{
|
|
// 首页
|
|
public function index()
|
|
{
|
|
// 获取文章列表
|
|
$articles = Db::table('yz_article')
|
|
->where('delete_time', null)
|
|
->where('status', '<>', 3)
|
|
->order('id DESC')
|
|
->select()
|
|
->toArray();
|
|
|
|
$articleList = [];
|
|
foreach ($articles as $article) {
|
|
$cate = $article['cate'];
|
|
$cateName = Db::table('yz_article_category')
|
|
->where('id', $cate)
|
|
->where('delete_time', null)
|
|
->where('status', 1)
|
|
->value('name');
|
|
|
|
if ($cateName) { // 只添加有效的分类
|
|
if (!isset($articleList[$cateName])) {
|
|
$articleList[$cateName] = [];
|
|
}
|
|
$articleList[$cateName][] = $article;
|
|
}
|
|
}
|
|
|
|
// 调试信息
|
|
trace('Articles: ' . json_encode($articles, JSON_UNESCAPED_UNICODE));
|
|
trace('ArticleList: ' . json_encode($articleList, JSON_UNESCAPED_UNICODE));
|
|
|
|
// 将变量传递给视图
|
|
View::assign([
|
|
'articleList' => $articleList,
|
|
]);
|
|
return view('index');
|
|
}
|
|
|
|
// 文章列表
|
|
public function articlelist()
|
|
{
|
|
$articles = Db::table('yz_article')
|
|
->where('delete_time', null)
|
|
->where('status', 1)
|
|
->order('id DESC')
|
|
->select()
|
|
->toArray();
|
|
|
|
$articleList = [];
|
|
foreach ($articles as $article) {
|
|
$cate = $article['cate'];
|
|
$cateName = Db::table('yz_article_category')->where('id', $cate)->value('name');
|
|
if (!isset($articleList[$cateName])) {
|
|
$articleList[$cateName] = [];
|
|
}
|
|
$articleList[$cateName][] = $article;
|
|
}
|
|
|
|
View::assign('articleList', $articleList);
|
|
return View::fetch();
|
|
}
|
|
}
|