mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-22 19:44:02 +08:00
web module采用更加灵活的模板继承结构
This commit is contained in:
parent
0342331d89
commit
46b817c416
@ -4,16 +4,34 @@ namespace App\Http\Web\Controllers;
|
|||||||
|
|
||||||
use App\Caches\NavTreeList as NavTreeListCache;
|
use App\Caches\NavTreeList as NavTreeListCache;
|
||||||
use App\Caches\Setting as SettingCache;
|
use App\Caches\Setting as SettingCache;
|
||||||
|
use App\Library\Seo as SiteSeo;
|
||||||
use App\Services\Auth\Web as WebAuth;
|
use App\Services\Auth\Web as WebAuth;
|
||||||
use App\Traits\Response as ResponseTrait;
|
use App\Traits\Response as ResponseTrait;
|
||||||
use App\Traits\Security as SecurityTrait;
|
use App\Traits\Security as SecurityTrait;
|
||||||
use Phalcon\Mvc\Dispatcher;
|
use Phalcon\Mvc\Dispatcher;
|
||||||
|
use Yansongda\Supports\Collection;
|
||||||
|
|
||||||
class Controller extends \Phalcon\Mvc\Controller
|
class Controller extends \Phalcon\Mvc\Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $siteSettings;
|
/**
|
||||||
protected $navList;
|
* @var SiteSeo
|
||||||
|
*/
|
||||||
|
protected $seo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Collection
|
||||||
|
*/
|
||||||
|
protected $site;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Collection
|
||||||
|
*/
|
||||||
|
protected $nav;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Collection
|
||||||
|
*/
|
||||||
protected $authUser;
|
protected $authUser;
|
||||||
|
|
||||||
use ResponseTrait, SecurityTrait;
|
use ResponseTrait, SecurityTrait;
|
||||||
@ -27,8 +45,9 @@ class Controller extends \Phalcon\Mvc\Controller
|
|||||||
|
|
||||||
$this->checkRateLimit();
|
$this->checkRateLimit();
|
||||||
|
|
||||||
$this->siteSettings = $this->getSiteSettings();
|
$this->seo = $this->getSiteSeo();
|
||||||
$this->navList = $this->getNavList();
|
$this->site = $this->getSiteSettings();
|
||||||
|
$this->nav = $this->getNavList();
|
||||||
$this->authUser = $this->getAuthUser();
|
$this->authUser = $this->getAuthUser();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -36,10 +55,12 @@ class Controller extends \Phalcon\Mvc\Controller
|
|||||||
|
|
||||||
public function initialize()
|
public function initialize()
|
||||||
{
|
{
|
||||||
|
$this->seo->setTitle($this->site->title);
|
||||||
|
|
||||||
|
$this->view->setVar('seo', $this->seo);
|
||||||
|
$this->view->setVar('site', $this->site);
|
||||||
|
$this->view->setVar('nav', $this->nav);
|
||||||
$this->view->setVar('auth_user', $this->authUser);
|
$this->view->setVar('auth_user', $this->authUser);
|
||||||
$this->view->setVar('site_settings', $this->siteSettings);
|
|
||||||
$this->view->setVar('top_nav_list', $this->navList->top);
|
|
||||||
$this->view->setVar('btm_nav_list', $this->navList->bottom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAuthUser()
|
protected function getAuthUser()
|
||||||
@ -66,4 +87,9 @@ class Controller extends \Phalcon\Mvc\Controller
|
|||||||
return $cache->get('site');
|
return $cache->get('site');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getSiteSeo()
|
||||||
|
{
|
||||||
|
return new SiteSeo();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,9 @@ class IndexController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
|
$this->seo->setKeywords($this->site->keywords);
|
||||||
|
$this->seo->setDescription($this->site->description);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
{{ flashSession.output() }}
|
|
||||||
|
|
||||||
<div class="layui-fluid">
|
<div class="layui-fluid">
|
||||||
<div class="kg-tips">
|
<div class="kg-tips">
|
||||||
<i class="layui-icon layui-icon-face-surprised"></i>
|
<i class="layui-icon layui-icon-face-surprised"></i>
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
{{ flashSession.output() }}
|
|
||||||
|
|
||||||
<div class="layui-fluid">
|
<div class="layui-fluid">
|
||||||
<div class="kg-tips">
|
<div class="kg-tips">
|
||||||
<i class="layui-icon layui-icon-face-surprised"></i>
|
<i class="layui-icon layui-icon-face-surprised"></i>
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
{{ flashSession.output() }}
|
|
||||||
|
|
||||||
<div class="layui-fluid">
|
<div class="layui-fluid">
|
||||||
<div class="kg-tips">
|
<div class="kg-tips">
|
||||||
<i class="layui-icon layui-icon-face-surprised"></i>
|
<i class="layui-icon layui-icon-face-surprised"></i>
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
{{ flashSession.output() }}
|
|
||||||
|
|
||||||
<div class="layui-fluid">
|
<div class="layui-fluid">
|
||||||
<div class="kg-tips">
|
<div class="kg-tips">
|
||||||
<i class="layui-icon layui-icon-face-surprised"></i>
|
<i class="layui-icon layui-icon-face-surprised"></i>
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
{{ flashSession.output() }}
|
|
||||||
|
|
||||||
<div class="layui-fluid">
|
<div class="layui-fluid">
|
||||||
<div class="kg-tips">
|
<div class="kg-tips">
|
||||||
<i class="layui-icon layui-icon-face-surprised"></i>
|
<i class="layui-icon layui-icon-face-surprised"></i>
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
{{ flashSession.output() }}
|
|
||||||
|
|
||||||
<div class="layui-fluid">
|
<div class="layui-fluid">
|
||||||
<div class="kg-tips">
|
<div class="kg-tips">
|
||||||
<i class="layui-icon layui-icon-face-surprised"></i>
|
<i class="layui-icon layui-icon-face-surprised"></i>
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
|
||||||
<title>{{ site_settings.title }}</title>
|
|
||||||
{{ icon_link("favicon.ico") }}
|
|
||||||
{{ css_link("lib/layui/css/layui.css") }}
|
|
||||||
{{ js_include("lib/layui/layui.js") }}
|
|
||||||
</head>
|
|
||||||
<body class="layui-layout-body">
|
|
||||||
{{ content() }}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,5 +0,0 @@
|
|||||||
<div class="page-header">
|
|
||||||
<h1>Congratulations!</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h1>I am home error404 page</h1>
|
|
@ -1 +1,21 @@
|
|||||||
|
{% extends "templates/base.volt" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
<img src="/qr/img?text=http://ctc.koogua.com">
|
<img src="/qr/img?text=http://ctc.koogua.com">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block inline_css %}
|
||||||
|
<style>
|
||||||
|
.ok {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block inline_js %}
|
||||||
|
<script>
|
||||||
|
function ok() {
|
||||||
|
console.log("fuck");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
@ -6,10 +6,9 @@
|
|||||||
<title>出错啦</title>
|
<title>出错啦</title>
|
||||||
{{ icon_link("favicon.ico") }}
|
{{ icon_link("favicon.ico") }}
|
||||||
{{ css_link("lib/layui/css/layui.css") }}
|
{{ css_link("lib/layui/css/layui.css") }}
|
||||||
{{ css_link("web/css/style.css") }}
|
{{ css_link("web/css/error.css") }}
|
||||||
{{ js_include("lib/layui/layui.js") }}
|
|
||||||
</head>
|
</head>
|
||||||
<body class="layui-layout-body">
|
<body>
|
||||||
{{ content() }}
|
{{ content() }}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
21
app/Http/Web/Views/templates/base.volt
Normal file
21
app/Http/Web/Views/templates/base.volt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||||
|
<meta name="keywords" content="{{ seo.getKeywords() }}">
|
||||||
|
<meta name="description" content="{{ seo.getDescription() }}">
|
||||||
|
<title>{{ seo.getTitle() }}</title>
|
||||||
|
{{ icon_link("favicon.ico") }}
|
||||||
|
{{ css_link("lib/layui/css/layui.css") }}
|
||||||
|
{{ css_link("web/css/style.css") }}
|
||||||
|
{% block header_css %}{% endblock %}
|
||||||
|
{% block inline_css %}{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
{{ js_include("lib/layui/layui.js") }}
|
||||||
|
{% block footer_js %}{% endblock %}
|
||||||
|
{% block inline_js %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
78
app/Library/Seo.php
Normal file
78
app/Library/Seo.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Library;
|
||||||
|
|
||||||
|
class Seo
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string 标题
|
||||||
|
*/
|
||||||
|
protected $title = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string 关键字
|
||||||
|
*/
|
||||||
|
protected $keywords = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string 描述
|
||||||
|
*/
|
||||||
|
protected $description = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string 标题分隔符
|
||||||
|
*/
|
||||||
|
protected $titleSeparator = ' - ';
|
||||||
|
|
||||||
|
public function setTitle($title)
|
||||||
|
{
|
||||||
|
$this->title = $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setKeywords($keywords)
|
||||||
|
{
|
||||||
|
$this->keywords = $keywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription($description)
|
||||||
|
{
|
||||||
|
$this->description = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTitleSeparator($titleSeparator)
|
||||||
|
{
|
||||||
|
$this->titleSeparator = $titleSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function appendTitle($text)
|
||||||
|
{
|
||||||
|
$this->title = $this->title . $this->titleSeparator . $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prependTitle($text)
|
||||||
|
{
|
||||||
|
$this->title = $text . $this->titleSeparator . $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKeywords()
|
||||||
|
{
|
||||||
|
return $this->keywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription()
|
||||||
|
{
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitleSeparator()
|
||||||
|
{
|
||||||
|
return $this->titleSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
app/Providers/Seo.php
Normal file
19
app/Providers/Seo.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Library\Util\Seo as AppSeo;
|
||||||
|
|
||||||
|
class Seo extends Provider
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $serviceName = 'seo';
|
||||||
|
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->di->setShared($this->serviceName, function () {
|
||||||
|
return new AppSeo();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -22,6 +22,10 @@ class Volt extends Provider
|
|||||||
|
|
||||||
$compiler = $volt->getCompiler();
|
$compiler = $volt->getCompiler();
|
||||||
|
|
||||||
|
$compiler->addFunction('static_url', function ($resolvedArgs) {
|
||||||
|
return 'kg_static_url(' . $resolvedArgs . ')';
|
||||||
|
});
|
||||||
|
|
||||||
$compiler->addFunction('icon_link', function ($resolvedArgs) {
|
$compiler->addFunction('icon_link', function ($resolvedArgs) {
|
||||||
return 'kg_icon_link(' . $resolvedArgs . ')';
|
return 'kg_icon_link(' . $resolvedArgs . ')';
|
||||||
});
|
});
|
||||||
|
@ -38,34 +38,6 @@
|
|||||||
color: green;
|
color: green;
|
||||||
}
|
}
|
||||||
|
|
||||||
.kg-tips {
|
|
||||||
margin-top: 30px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.kg-tips .layui-icon-face-surprised {
|
|
||||||
display: inline-block;
|
|
||||||
font-size: 200px;
|
|
||||||
color: #393D49;
|
|
||||||
}
|
|
||||||
|
|
||||||
.kg-tips .layui-text {
|
|
||||||
width: 500px;
|
|
||||||
margin: 30px auto;
|
|
||||||
padding-top: 20px;
|
|
||||||
border-top: 5px solid #009688;
|
|
||||||
}
|
|
||||||
|
|
||||||
.kg-tips h1 {
|
|
||||||
font-size: 100px;
|
|
||||||
line-height: 100px;
|
|
||||||
color: #009688;
|
|
||||||
}
|
|
||||||
|
|
||||||
.kg-tips .layui-text span {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.kg-side-menu-bar {
|
.kg-side-menu-bar {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
27
public/static/web/css/error.css
Normal file
27
public/static/web/css/error.css
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
.kg-tips {
|
||||||
|
margin-top: 30px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kg-tips .layui-icon-face-surprised {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 200px;
|
||||||
|
color: #393D49;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kg-tips .layui-text {
|
||||||
|
width: 500px;
|
||||||
|
margin: 30px auto;
|
||||||
|
padding-top: 20px;
|
||||||
|
border-top: 5px solid #009688;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kg-tips h1 {
|
||||||
|
font-size: 100px;
|
||||||
|
line-height: 100px;
|
||||||
|
color: #009688;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kg-tips .layui-text span {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
@ -1,27 +0,0 @@
|
|||||||
.kg-tips {
|
|
||||||
margin-top: 30px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.kg-tips .layui-icon-face-surprised {
|
|
||||||
display: inline-block;
|
|
||||||
font-size: 200px;
|
|
||||||
color: #393D49;
|
|
||||||
}
|
|
||||||
|
|
||||||
.kg-tips .layui-text {
|
|
||||||
width: 500px;
|
|
||||||
margin: 30px auto;
|
|
||||||
padding-top: 20px;
|
|
||||||
border-top: 5px solid #009688;
|
|
||||||
}
|
|
||||||
|
|
||||||
.kg-tips h1 {
|
|
||||||
font-size: 100px;
|
|
||||||
line-height: 100px;
|
|
||||||
color: #009688;
|
|
||||||
}
|
|
||||||
|
|
||||||
.kg-tips .layui-text span {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user