初始化应用

This commit is contained in:
augushong
2020-08-08 22:02:18 +08:00
parent 3bc46a4b9c
commit d263417b51
34 changed files with 181 additions and 1411 deletions

View File

@@ -10,58 +10,10 @@ use think\helper\Str;
class BaseController extends AppBaseController
{
/**
* 是否使用多模板
* 仅当名称为空或者指定名称有效,
* 使用跨应用,跨控制器,引用模板路径的写法时无效
*
* @var boolean
*/
protected $isUseTpls = true;
protected $indexTplName = '';
protected $indexTplMethod = '';
protected $indexTplMethodCurrentAction = '';
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,93 +0,0 @@
<?php
declare(strict_types=1);
namespace app\index\controller;
use app\model\Category as ModelCategory;
use think\Request;
class Category extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
$model_category = ModelCategory::with('posts.post')->find($id);
$this->assign('category',$model_category);
return $this->fetch('read'.$model_category->getData('tpl_name'));
}
/**
* 显示编辑资源表单页.
*
* @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)
{
//
}
}

View File

@@ -20,52 +20,17 @@ class Common extends BaseController
$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 __blog()
{
$list_header_nav = Nav::where('type', 'blog_header_nav')->order('sort asc')->where('status', 1)->select();
View::assign('list_header_nav', $list_header_nav);
}
public function __documents()
{
$list_header_nav = Nav::where('type', 'document_header_nav')->order('sort asc')->where('status', 1)->select();
View::assign('list_header_nav', $list_header_nav);
}
public function __easyBlue()
{
$list_header_nav = Nav::where('type', 10)->order('sort asc')->where('status', 1)->select();
View::assign('list_header_nav', $list_header_nav);
$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_header_nav = Nav::where('type', 11)->order('sort asc')->where('status', 1)->select();
View::assign('list_header_nav', $list_header_nav);
$list_category_first_level = Category::where('level', 1)->where('status', 1)->where('type',3)->select();
$this->assign('list_category_first_level', $list_category_first_level);
View::assign('list_category_first_level', $list_category_first_level);
$list_nav_more = Nav::where('type', 8)->order('sort asc')->where('status', 1)->where('type',11)->select();
View::assign('list_nav_more', $list_nav_more);
$top_posts = Post::where('is_top',1)->limit(8)->where('type',3)->select();
$this->assign('top_posts',$top_posts);
View::assign('top_posts',$top_posts);
}
}

View File

@@ -6,6 +6,7 @@ use app\model\Category;
use app\model\Nav;
use app\model\Post;
use app\model\PostCategory;
use think\facade\View;
use think\Request;
class Index extends Common
@@ -19,44 +20,7 @@ class Index extends Common
{
//
return $this->fetch();
}
public function __blogIndex()
{
$list_category = Category::where('type','blog_post')->select();
$this->assign('list_category',$list_category);
$category_id = $this->request->param('category_id');
if(!empty($category_id)){
$model_list_post = Post::hasWhere('categorys',['category_id'=>$category_id])->order('sort desc');
}else{
$model_list_post = Post::order('sort desc');
}
$model_list_post->where('type','blog_post');
$list_post = $model_list_post->paginate();
$this->assign('list_post',$list_post);
}
public function __documentsIndex()
{
$list_index_documents_nav = Nav::where('type',9)->select();
$this->assign('list_index_documents_nav',$list_index_documents_nav);
}
public function __articlesIndex()
{
$sub_category = [];
if(!empty($this->request->param('category_id'))){
@@ -89,11 +53,14 @@ class Index extends Common
$list_post = $model_post->paginate();
$this->assign('sub_category',$sub_category);
View::assign('sub_category',$sub_category);
$this->assign('list_post',$list_post);
View::assign('list_post',$list_post);
return View::fetch();
}
/**
* 显示创建资源表单页.
*

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace app\index\controller;
use app\model\Post as ModelPost;
use think\facade\View;
use think\Request;
class Post extends Common
@@ -52,23 +53,12 @@ class Post extends Common
$model_post = ModelPost::find($id);
$this->assign('post', $model_post);
View::assign('post', $model_post);
return $this->fetch();
return View::fetch();
}
public function __documentsRead()
{
$category_id = $this->request->param('category_id',0);
$list_post = [];
if(!empty($category_id)){
$list_post = ModelPost::hasWhere('categorys',['category_id'=>$category_id])->order('sort desc')->select();
}
$this->assign('list_post',$list_post);
}
/**
* 显示编辑资源表单页.