完成资讯主题

This commit is contained in:
augushong
2020-04-20 21:24:19 +08:00
parent cd7911bb63
commit 448c4d0d60
30 changed files with 848 additions and 347 deletions

View File

@@ -1,4 +1,5 @@
<?php
namespace app\index\controller;
use app\BaseController as AppBaseController;
@@ -9,38 +10,58 @@ use think\helper\Str;
class BaseController extends AppBaseController
{
/**
* 是否使用多模板
* 仅当名称为空或者指定名称有效,
* 使用跨应用,跨控制器,引用模板路径的写法时无效
*
* @var boolean
*/
protected $isUseTpls = true;
/**
* 是否使用多模板
* 仅当名称为空或者指定名称有效,
* 使用跨应用,跨控制器,引用模板路径的写法时无效
*
* @var boolean
*/
protected $isUseTpls = true;
public function assign($template,$value)
{
return View::assign($template,$value);
}
protected $indexTplName = '';
protected $indexTplMethod = '';
protected $indexTplMethodCurrentAction = '';
public function fetch($template = '',$vars = [])
{
if($this->isUseTpls && strpos($template,'@') === false && stripos($template,'/') === false){
if($template === ''){
$config_auto_rule = Config::get('view.auto_rule');
if (2 == $config_auto_rule) {
$template = $this->request->action(true);
} elseif (3 == $config_auto_rule) {
$template = $this->request->action();
} else {
$template = Str::snake($this->request->action());
}
}
return View::fetch(get_system_config('index_tpl_name').$template,$vars);
}else{
return View::fetch($template,$vars);
public function initialize()
{
parent::initialize();
$this->indexTplName = get_system_config('index_tpl_name');
$this->indexTplMethod = '__'.Str::camel($this->indexTplName);
$this->indexTplMethodCurrentAction = $this->indexTplMethod.Str::studly($this->request->action());
}
public function assign($template, $value)
{
return View::assign($template, $value);
}
public function fetch($template = '', $vars = [])
{
if ($this->isUseTpls && strpos($template, '@') === false && stripos($template, '/') === false) {
if ($template === '') {
$config_auto_rule = Config::get('view.auto_rule');
if (2 == $config_auto_rule) {
$template = $this->request->action(true);
} elseif (3 == $config_auto_rule) {
$template = $this->request->action();
} else {
$template = Str::snake($this->request->action());
}
}
return View::fetch($this->indexTplName . $template, $vars);
} else {
return View::fetch($template, $vars);
}
}
}

View File

@@ -1,25 +1,54 @@
<?php
namespace app\index\controller;
use app\model\Category;
use app\model\Nav;
use think\facade\View;
use think\helper\Str;
class Common extends BaseController
class Common extends BaseController
{
public function initialize()
{
parent::initialize();
$list_header_nav = Nav::where('type',1)->order('sort asc')->where('status',1)->select();
View::assign('list_header_nav',$list_header_nav);
$list_nav_slide = Nav::where('type',3)->order('sort asc')->where('status',1)->select();
View::assign('list_nav_slide',$list_nav_slide);
$list_nav_index_block_1 = Nav::where('type',6)->order('sort asc')->where('status',1)->select();
View::assign('list_nav_index_block_1',$list_nav_index_block_1);
$list_nav_index_block_2 = Nav::where('type',7)->order('sort asc')->where('status',1)->select();
View::assign('list_nav_index_block_2',$list_nav_index_block_2);
$list_nav_friend_url = Nav::where('type',2)->order('sort asc')->where('status',1)->select();
View::assign('list_nav_friend_url',$list_nav_friend_url);
$list_header_nav = Nav::where('type', 1)->order('sort asc')->where('status', 1)->select();
View::assign('list_header_nav', $list_header_nav);
$list_nav_slide = Nav::where('type', 3)->order('sort asc')->where('status', 1)->select();
View::assign('list_nav_slide', $list_nav_slide);
$list_nav_friend_url = Nav::where('type', 2)->order('sort asc')->where('status', 1)->select();
View::assign('list_nav_friend_url', $list_nav_friend_url);
if (!empty($this->indexTplMethod)) {
if (method_exists($this, $this->indexTplMethod)) {
$this->{$this->indexTplMethod}();
}
}
if (!empty($this->indexTplMethodCurrentAction)) {
if (method_exists($this, $this->indexTplMethodCurrentAction)) {
$this->{$this->indexTplMethodCurrentAction}();
}
}
}
public function __easyBlue()
{
$list_nav_index_block_1 = Nav::where('type', 6)->order('sort asc')->where('status', 1)->select();
View::assign('list_nav_index_block_1', $list_nav_index_block_1);
$list_nav_index_block_2 = Nav::where('type', 7)->order('sort asc')->where('status', 1)->select();
View::assign('list_nav_index_block_2', $list_nav_index_block_2);
}
public function __articles()
{
$list_category_first_level = Category::where('level', 1)->where('status', 1)->select();
$this->assign('list_category_first_level', $list_category_first_level);
$list_nav_more = Nav::where('type', 8)->order('sort asc')->where('status', 1)->select();
View::assign('list_nav_more', $list_nav_more);
}
}

View File

@@ -2,86 +2,126 @@
namespace app\index\controller;
use think\facade\View;
use app\model\Category;
use app\model\Post;
use app\model\PostCategory;
use think\Request;
class Index extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
return $this->fetch();
return $this->fetch();
}
public function __articlesIndex()
{
$sub_category = [];
if(!empty($this->request->param('category_id'))){
$sub_category = Category::where('pid',$this->request->param('category_id'))->select();
if(empty($this->request->param('sub_category_id'))){
$categorys = [$this->request->param('category_id')];
$categorys = array_merge($categorys,array_column((array)Category::getListLevel($this->request->param('category_id')),'id'));
$categorys_where = PostCategory::whereIn('category_id',$categorys);
$model_post = Post::hasWhere('categorys',$categorys_where)->where('status',1)->order('id desc');
}else{
$model_post = Post::hasWhere('categorys',['category_id'=>$this->request->param('sub_category_id')])->where('status',1)->order('id desc');
}
}else{
$model_post = Post::where('status',1)->order('id desc');
}
$keywords = $this->request->param('keywords');
if(!empty($keywords)){
$model_post->whereLike('title|desc',"%$keywords%");
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
$list_post = $model_post->paginate();
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
}
$this->assign('sub_category',$sub_category);
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
$this->assign('list_post',$list_post);
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
/**
* 保存新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* 保存新的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
}
/**
* 显示指定资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
}
}