Skip to content

Commit bd41634

Browse files
rootroot
root
authored and
root
committed
add
1 parent 6929a85 commit bd41634

File tree

20 files changed

+640
-39
lines changed

20 files changed

+640
-39
lines changed

app/appfront/config/appfront.php

+5
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@
1111
'modules'=>$modules,
1212
/* only config in front web */
1313
'bootstrap' => ['store'],
14+
'params' => [
15+
/* appfront base theme dir */
16+
'appfrontBaseTheme' => '@fecshop/app/appfront/theme/base/front',
17+
'appfrontBaseLayoutName'=> 'main.php',
18+
],
1419
];

app/appfront/modules/AppfrontController.php

+26-33
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,48 @@
11
<?php
22
namespace fecshop\app\appfront\modules;
33
use Yii;
4+
use fec\helpers\CConfig;
45
use fec\controllers\FecController;
56
use yii\base\InvalidValueException;
67
class AppfrontController extends FecController
78
{
8-
protected $_currentLayoutFile = 'main.php';
9-
protected $_themeDir = '@fecshop/app/appfront/theme/base/default';
109

11-
public function beforeAction($action){
12-
if(parent::beforeAction($action)){
13-
Yii::$app->page->theme->fecshopThemeDir = Yii::getAlias($this->_themeDir);
14-
return true;
10+
/**
11+
* init theme component property : $fecshopThemeDir and $layoutFile
12+
* $fecshopThemeDir is appfront base theme directory.
13+
* layoutFile is current layout relative path.
14+
*/
15+
public function init(){
16+
if(!Yii::$app->page->theme->fecshopThemeDir){
17+
Yii::$app->page->theme->fecshopThemeDir = Yii::getAlias(CConfig::param('appfrontBaseTheme'));
18+
}
19+
if(!Yii::$app->page->theme->layoutFile){
20+
Yii::$app->page->theme->layoutFile = CConfig::param('appfrontBaseLayoutName');
1521
}
1622
}
1723

18-
public function render($view, $params = []){
19-
$viewFile = '';
20-
$relativeFile = $this->module->id.'/'.$this->id.'/'.$view.'.php';
21-
$absoluteDir = Yii::$app->page->theme->getThemeDirArr();
22-
foreach($absoluteDir as $dir){
23-
if($dir){
24-
$file = $dir.'/'.$relativeFile;
25-
if(file_exists($file)){
26-
$viewFile = $file;
27-
break;
28-
}
29-
}
30-
}
31-
if(!$viewFile){
32-
$notExistFile = [];
33-
foreach($absoluteDir as $dir){
34-
if($dir){
35-
$file = $dir.'/'.$relativeFile;
36-
$notExistFile[] = $file;
37-
}
38-
}
39-
throw new InvalidValueException('view file is not exist in'.implode(',',$notExistFile));
40-
}
41-
$content = $this->getView()->renderFile($viewFile, $params, $this);
24+
/**
25+
* @property $view|String , (only) view file name ,by this module id, this controller id , generate view relative path.
26+
* @property $params|Array,
27+
* 1.get exist view file from mutil theme by theme protity.
28+
* 2.get content by yii view compontent function renderFile() ,
29+
*/
30+
public function render($view, $params = []){
31+
$viewFile = Yii::$app->page->theme->getViewFile($view);
32+
$content = Yii::$app->view->renderFile($viewFile, $params, $this);
4233
return $this->renderContent($content);
4334
}
4435

45-
36+
/**
37+
* Get current layoutFile absolute path from mutil theme dir by protity
38+
*/
4639
public function findLayoutFile($view){
4740
$layoutFile = '';
48-
$relativeFile = '/layouts/'.$this->_currentLayoutFile;
41+
$relativeFile = 'layouts/'.Yii::$app->page->theme->layoutFile;
4942
$absoluteDir = Yii::$app->page->theme->getThemeDirArr();
5043
foreach($absoluteDir as $dir){
5144
if($dir){
52-
$file = $dir.$relativeFile;
45+
$file = $dir.'/'.$relativeFile;
5346
if(file_exists($file)){
5447
$layoutFile = $file;
5548
return $layoutFile;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
namespace fecshop\app\appfront\modules\Cms\block\widget;
3+
use Yii;
4+
use fecshop\app\appfront\modules\AppfrontController;
5+
class Test
6+
{
7+
public $terry;
8+
# ÍøÕ¾ÐÅÏ¢¹ÜÀí
9+
public function getLastData()
10+
{
11+
return [
12+
'i' => $this->terry,
13+
'love' => 'loves',
14+
'you' => 'terry',
15+
];
16+
}
17+
}
18+
19+
20+

app/appfront/modules/Cms/controllers/HomeController.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<?php
22
namespace fecshop\app\appfront\modules\Cms\controllers;
3+
use Yii;
34
use fecshop\app\appfront\modules\AppfrontController;
45
class HomeController extends AppfrontController
56
{
6-
protected $_currentLayoutFile = 'home.php';
7+
78
# ÍøÕ¾ÐÅÏ¢¹ÜÀí
89
public function actionIndex()
910
{
1011
//echo 111;exit;
12+
echo Yii::$app->page->widget->render('love');
13+
Yii::$app->page->theme->layoutFile = 'home.php';
1114
return $this->render($this->action->id,[]);
1215
}
1316
}

app/appfront/theme/BaseAsset.php

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* FecShop file.
4+
* @link http://www.fecshop.com/
5+
* @copyright Copyright (c) 2016 FecShop Software LLC
6+
* @license http://www.fecshop.com/license/
7+
*/
8+
namespace fecshop\app\appfront\theme\base\front\assets;
9+
use yii\web\AssetBundle;
10+
/**
11+
* Page services
12+
* @author Terry Zhao <2358269014@qq.com>
13+
* @since 1.0
14+
*/
15+
class AppAsset extends AssetBundle
16+
{
17+
public $basePath = '@webroot';
18+
public $baseUrl = '@web';
19+
public $css = [];
20+
public $cssOptions = [ 'position' => \yii\web\View::POS_HEAD ];
21+
public $js = [];
22+
public $jsOptions = [ 'position' => \yii\web\View::POS_END ]; # POS_HEAD
23+
public $depends = [
24+
//'fecshop\app\appfront\theme\BaseAsset',
25+
'fecshop\app\appfront\theme\base\front\assets\AppFrontAsset',
26+
'fecshop\app\appfront\theme\base\front\assets\IEAsset',
27+
'fecshop\app\appfront\theme\base\front\assets\LtIE9Asset',
28+
];
29+
}
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* FecShop file.
4+
* @link http://www.fecshop.com/
5+
* @copyright Copyright (c) 2016 FecShop Software LLC
6+
* @license http://www.fecshop.com/license/
7+
*/
8+
namespace fecshop\app\appfront\theme\base\front\assets;
9+
use yii\web\AssetBundle;
10+
/**
11+
* Page services
12+
* @author Terry Zhao <2358269014@qq.com>
13+
* @since 1.0
14+
*/
15+
class AppFrontAsset extends AssetBundle
16+
{
17+
public $sourcePath = '@fecshop/app/appfront/theme/base/front/assets';
18+
public $css = [
19+
'css/style.css',
20+
];
21+
public $js = [
22+
'js/jquery-3.0.0.min.js',
23+
];
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* FecShop file.
4+
* @link http://www.fecshop.com/
5+
* @copyright Copyright (c) 2016 FecShop Software LLC
6+
* @license http://www.fecshop.com/license/
7+
*/
8+
namespace fecshop\app\appfront\theme\base\front\assets;
9+
use yii\web\AssetBundle;
10+
/**
11+
* Page services
12+
* @author Terry Zhao <2358269014@qq.com>
13+
* @since 1.0
14+
*/
15+
class IEAsset extends AssetBundle
16+
{
17+
public $sourcePath = '@fecshop/app/appfront/theme/base/front/assets';
18+
public $cssOptions = ['condition' => 'if IE'];
19+
public $css = [
20+
'css/ie.css',
21+
];
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* FecShop file.
4+
* @link http://www.fecshop.com/
5+
* @copyright Copyright (c) 2016 FecShop Software LLC
6+
* @license http://www.fecshop.com/license/
7+
*/
8+
namespace fecshop\app\appfront\theme\base\front\assets;
9+
use yii\web\AssetBundle;
10+
/**
11+
* Page services
12+
* @author Terry Zhao <2358269014@qq.com>
13+
* @since 1.0
14+
*/
15+
class LtIE9Asset extends AssetBundle
16+
{
17+
public $sourcePath = '@fecshop/app/appfront/theme/base/front/assets';
18+
public $cssOptions = ['condition' => 'lt IE 9'];
19+
public $css = [
20+
'css/ltie9.css',
21+
];
22+
/*
23+
public $jsOptions = [
24+
//'position' => \yii\web\View::POS_END ,
25+
'condition' => 'lt IE 9'
26+
];
27+
28+
public $js = [
29+
//'dwz_jui-master/js/speedup.js',
30+
//'dwz_jui-master/jquery-1.11.3.min.js',
31+
];
32+
public $depends = [
33+
34+
];
35+
*/
36+
37+
}

app/appfront/theme/base/front/assets/css/ie.css

Whitespace-only changes.

app/appfront/theme/base/front/assets/css/ltie9.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.body{
2+
color:#ccc;
3+
font-size:12px;
4+
}

app/appfront/theme/base/front/assets/js/jquery-3.0.0.min.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
33333
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/* @var $this \yii\web\View */
3+
/* @var $content string */
4+
use fecshop\app\appfront\theme\base\front\assets\AppAsset;
5+
AppAsset::register($this);
6+
//var_dump( $cssAndJs['js']);exit;
7+
//$this->assetBundles["fecadmin\myassets\AppAsset"]->js = $cssAndJs['js'];
8+
//$this->assetBundles["fecadmin\myassets\AppAsset"]->css = $cssAndJs['css'];
9+
10+
?>
11+
<?php $this->beginPage() ?>
12+
<!DOCTYPE html>
13+
<html lang="<?= Yii::$app->language ?>" xmlns="http://www.w3.org/1999/xhtml">
14+
<head>
15+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
16+
<meta name="viewport" content="width=device-width, initial-scale=1">
17+
<?php $this->head() ?>
18+
<?php
19+
//$publishedPath = $this->assetManager->publish('@fecadmin/myassets/dwz_jui-master/dwz.frag.xml');
20+
?>
21+
</head>
22+
<body>
23+
<?php $this->beginBody() ?>
24+
<div id="layout">
25+
<div id="header">
26+
27+
</div>
28+
<?= $content ?>
29+
</div>
30+
<footer class="footer">
31+
<div class="container">
32+
33+
</div>
34+
</footer>
35+
<?php $this->endBody() ?>
36+
</body>
37+
</html>
38+
<?php $this->endPage() ?>

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"php": ">=5.4.0",
2424
"yiisoft/yii2": ">=2.0.6" ,
2525
"fancyecommerce/fec_admin":"~1.3.5.3",
26-
"yiisoft/yii2-mongodb": "~2.0.0"
26+
"yiisoft/yii2-mongodb": "~2.0.0" ,
27+
"skeeks/yii2-assets-auto-compress": "*"
2728
},
2829
"autoload": {
2930
"psr-4": {

config/services/Page.php

+26-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,32 @@
2626
'theme' => [
2727
'class' => 'fecshop\services\page\Theme',
2828
],
29-
29+
'widget' => [
30+
'class' => 'fecshop\services\page\Widget',
31+
# 定义默认方法,也就是widgetConfig 里面各个部件里面的method如果没有填写
32+
# 则使用该配置。
33+
# 'defaultObMethod' => 'getLastData',
34+
35+
'widgetConfig' => [
36+
'menu' =>[
37+
# 必填
38+
'class' => 'fec\block\TestMenu',
39+
# view 的绝对路径配置方式
40+
'view' => '@fec/views/testmenu/index.php',
41+
# 下面为选填
42+
'method'=> 'getLastData',
43+
'terry1'=> 'My1',
44+
'terry2'=> 'My2',
45+
],
46+
'love' => [
47+
'class' => 'fecshop\app\appfront\modules\Cms\block\widget\Test',
48+
# 根据多模板的优先级,依次去模板找查找该文件,直到找到这个文件。
49+
'view' => 'cms/home/test.php',
50+
'terry' => 'II',
51+
]
52+
]
53+
54+
],
3055
'currency' => [
3156
'class' => 'fecshop\services\page\Currency',
3257
'currencys' => [

0 commit comments

Comments
 (0)