Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Jul 3, 2016
1 parent 6929a85 commit bd41634
Show file tree
Hide file tree
Showing 20 changed files with 640 additions and 39 deletions.
5 changes: 5 additions & 0 deletions app/appfront/config/appfront.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
'modules'=>$modules,
/* only config in front web */
'bootstrap' => ['store'],
'params' => [
/* appfront base theme dir */
'appfrontBaseTheme' => '@fecshop/app/appfront/theme/base/front',
'appfrontBaseLayoutName'=> 'main.php',
],
];
59 changes: 26 additions & 33 deletions app/appfront/modules/AppfrontController.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
<?php
namespace fecshop\app\appfront\modules;
use Yii;
use fec\helpers\CConfig;
use fec\controllers\FecController;
use yii\base\InvalidValueException;
class AppfrontController extends FecController
{
protected $_currentLayoutFile = 'main.php';
protected $_themeDir = '@fecshop/app/appfront/theme/base/default';

public function beforeAction($action){
if(parent::beforeAction($action)){
Yii::$app->page->theme->fecshopThemeDir = Yii::getAlias($this->_themeDir);
return true;
/**
* init theme component property : $fecshopThemeDir and $layoutFile
* $fecshopThemeDir is appfront base theme directory.
* layoutFile is current layout relative path.
*/
public function init(){
if(!Yii::$app->page->theme->fecshopThemeDir){
Yii::$app->page->theme->fecshopThemeDir = Yii::getAlias(CConfig::param('appfrontBaseTheme'));
}
if(!Yii::$app->page->theme->layoutFile){
Yii::$app->page->theme->layoutFile = CConfig::param('appfrontBaseLayoutName');
}
}

public function render($view, $params = []){
$viewFile = '';
$relativeFile = $this->module->id.'/'.$this->id.'/'.$view.'.php';
$absoluteDir = Yii::$app->page->theme->getThemeDirArr();
foreach($absoluteDir as $dir){
if($dir){
$file = $dir.'/'.$relativeFile;
if(file_exists($file)){
$viewFile = $file;
break;
}
}
}
if(!$viewFile){
$notExistFile = [];
foreach($absoluteDir as $dir){
if($dir){
$file = $dir.'/'.$relativeFile;
$notExistFile[] = $file;
}
}
throw new InvalidValueException('view file is not exist in'.implode(',',$notExistFile));
}
$content = $this->getView()->renderFile($viewFile, $params, $this);
/**
* @property $view|String , (only) view file name ,by this module id, this controller id , generate view relative path.
* @property $params|Array,
* 1.get exist view file from mutil theme by theme protity.
* 2.get content by yii view compontent function renderFile() ,
*/
public function render($view, $params = []){
$viewFile = Yii::$app->page->theme->getViewFile($view);
$content = Yii::$app->view->renderFile($viewFile, $params, $this);
return $this->renderContent($content);
}


/**
* Get current layoutFile absolute path from mutil theme dir by protity
*/
public function findLayoutFile($view){
$layoutFile = '';
$relativeFile = '/layouts/'.$this->_currentLayoutFile;
$relativeFile = 'layouts/'.Yii::$app->page->theme->layoutFile;
$absoluteDir = Yii::$app->page->theme->getThemeDirArr();
foreach($absoluteDir as $dir){
if($dir){
$file = $dir.$relativeFile;
$file = $dir.'/'.$relativeFile;
if(file_exists($file)){
$layoutFile = $file;
return $layoutFile;
Expand Down
20 changes: 20 additions & 0 deletions app/appfront/modules/Cms/block/widget/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace fecshop\app\appfront\modules\Cms\block\widget;
use Yii;
use fecshop\app\appfront\modules\AppfrontController;
class Test
{
public $terry;
# ÍøÕ¾ÐÅÏ¢¹ÜÀí
public function getLastData()
{
return [
'i' => $this->terry,
'love' => 'loves',
'you' => 'terry',
];
}
}



5 changes: 4 additions & 1 deletion app/appfront/modules/Cms/controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php
namespace fecshop\app\appfront\modules\Cms\controllers;
use Yii;
use fecshop\app\appfront\modules\AppfrontController;
class HomeController extends AppfrontController
{
protected $_currentLayoutFile = 'home.php';

# ÍøÕ¾ÐÅÏ¢¹ÜÀí
public function actionIndex()
{
//echo 111;exit;
echo Yii::$app->page->widget->render('love');
Yii::$app->page->theme->layoutFile = 'home.php';
return $this->render($this->action->id,[]);
}
}
Expand Down
Empty file.
39 changes: 39 additions & 0 deletions app/appfront/theme/base/front/assets/AppAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* FecShop file.
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appfront\theme\base\front\assets;
use yii\web\AssetBundle;
/**
* Page services
* @author Terry Zhao <[email protected]>
* @since 1.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [];
public $cssOptions = [ 'position' => \yii\web\View::POS_HEAD ];
public $js = [];
public $jsOptions = [ 'position' => \yii\web\View::POS_END ]; # POS_HEAD
public $depends = [
//'fecshop\app\appfront\theme\BaseAsset',
'fecshop\app\appfront\theme\base\front\assets\AppFrontAsset',
'fecshop\app\appfront\theme\base\front\assets\IEAsset',
'fecshop\app\appfront\theme\base\front\assets\LtIE9Asset',
];
}










24 changes: 24 additions & 0 deletions app/appfront/theme/base/front/assets/AppFrontAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* FecShop file.
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appfront\theme\base\front\assets;
use yii\web\AssetBundle;
/**
* Page services
* @author Terry Zhao <[email protected]>
* @since 1.0
*/
class AppFrontAsset extends AssetBundle
{
public $sourcePath = '@fecshop/app/appfront/theme/base/front/assets';
public $css = [
'css/style.css',
];
public $js = [
'js/jquery-3.0.0.min.js',
];
}
23 changes: 23 additions & 0 deletions app/appfront/theme/base/front/assets/IEAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* FecShop file.
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appfront\theme\base\front\assets;
use yii\web\AssetBundle;
/**
* Page services
* @author Terry Zhao <[email protected]>
* @since 1.0
*/
class IEAsset extends AssetBundle
{
public $sourcePath = '@fecshop/app/appfront/theme/base/front/assets';
public $cssOptions = ['condition' => 'if IE'];
public $css = [
'css/ie.css',
];

}
37 changes: 37 additions & 0 deletions app/appfront/theme/base/front/assets/LtIE9Asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* FecShop file.
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appfront\theme\base\front\assets;
use yii\web\AssetBundle;
/**
* Page services
* @author Terry Zhao <[email protected]>
* @since 1.0
*/
class LtIE9Asset extends AssetBundle
{
public $sourcePath = '@fecshop/app/appfront/theme/base/front/assets';
public $cssOptions = ['condition' => 'lt IE 9'];
public $css = [
'css/ltie9.css',
];
/*
public $jsOptions = [
//'position' => \yii\web\View::POS_END ,
'condition' => 'lt IE 9'
];
public $js = [
//'dwz_jui-master/js/speedup.js',
//'dwz_jui-master/jquery-1.11.3.min.js',
];
public $depends = [
];
*/

}
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions app/appfront/theme/base/front/assets/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.body{
color:#ccc;
font-size:12px;
}
4 changes: 4 additions & 0 deletions app/appfront/theme/base/front/assets/js/jquery-3.0.0.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/appfront/theme/base/front/cms/home/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
33333
38 changes: 38 additions & 0 deletions app/appfront/theme/base/front/layouts/home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use fecshop\app\appfront\theme\base\front\assets\AppAsset;
AppAsset::register($this);
//var_dump( $cssAndJs['js']);exit;
//$this->assetBundles["fecadmin\myassets\AppAsset"]->js = $cssAndJs['js'];
//$this->assetBundles["fecadmin\myassets\AppAsset"]->css = $cssAndJs['css'];

?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php $this->head() ?>
<?php
//$publishedPath = $this->assetManager->publish('@fecadmin/myassets/dwz_jui-master/dwz.frag.xml');
?>
</head>
<body>
<?php $this->beginBody() ?>
<div id="layout">
<div id="header">

</div>
<?= $content ?>
</div>
<footer class="footer">
<div class="container">

</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"php": ">=5.4.0",
"yiisoft/yii2": ">=2.0.6" ,
"fancyecommerce/fec_admin":"~1.3.5.3",
"yiisoft/yii2-mongodb": "~2.0.0"
"yiisoft/yii2-mongodb": "~2.0.0" ,
"skeeks/yii2-assets-auto-compress": "*"
},
"autoload": {
"psr-4": {
Expand Down
27 changes: 26 additions & 1 deletion config/services/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,32 @@
'theme' => [
'class' => 'fecshop\services\page\Theme',
],

'widget' => [
'class' => 'fecshop\services\page\Widget',
# 定义默认方法,也就是widgetConfig 里面各个部件里面的method如果没有填写
# 则使用该配置。
# 'defaultObMethod' => 'getLastData',

'widgetConfig' => [
'menu' =>[
# 必填
'class' => 'fec\block\TestMenu',
# view 的绝对路径配置方式
'view' => '@fec/views/testmenu/index.php',
# 下面为选填
'method'=> 'getLastData',
'terry1'=> 'My1',
'terry2'=> 'My2',
],
'love' => [
'class' => 'fecshop\app\appfront\modules\Cms\block\widget\Test',
# 根据多模板的优先级,依次去模板找查找该文件,直到找到这个文件。
'view' => 'cms/home/test.php',
'terry' => 'II',
]
]

],
'currency' => [
'class' => 'fecshop\services\page\Currency',
'currencys' => [
Expand Down
Loading

0 comments on commit bd41634

Please sign in to comment.