提交 577672fe 编写于 作者: R root

built

上级 112fd4c8
<?php
return [
'cms' => [
'class' => '\fecshop\app\appadmin\modules\Cms\Module',
],
];
<?php
namespace fecshop\app\appadmin\interfaces\base;
interface AppadminbaseBlockEditInterface{
/**
* set Service ,like $this->_service = Yii::$app->cms->article;
*/
public function setService();
/**
* config edit array
*/
public function getEditArr();
}
\ No newline at end of file
<?php
namespace fecshop\app\appadmin\interfaces\base;
# use fecshop\app\appadmin\interfaces\base\AppadminbaseBlockInterface;
interface AppadminbaseBlockInterface{
public function getSearchArr();
public function getTableFieldArr();
}
\ No newline at end of file
此差异已折叠。
<?php
namespace fecshop\app\appadmin\modules;
use fec\helpers\CRequest;
use fec\helpers\CUrl;
use yii\base\Object;
use fecshop\app\appadmin\interfaces\base\AppadminbaseBlockEditInterface;
class AppadminbaseBlockEdit extends Object{
public $_param;
public $_primaryKey;
public $_one;
public $_service;
public $_textareas;
/**
* html input or text etc. , html name like: <input name="XXXX" />
*/
protected $_editFormData;
public function init(){
if(!($this instanceof AppadminbaseBlockEditInterface)){
echo json_encode(array(
'statusCode'=>'300',
'message'=>'Manageredit must implements fecshop\app\appadmin\interfaces\base\AppadminbaseBlockEditInterface',
));
exit;
}
$this->_editFormData = 'editFormData';
$this->setService();
$this->_param = CRequest::param();
$this->_primaryKey = $this->_service->getPrimaryKey();
$id = $this->_param[$this->_primaryKey];
$this->_one = $this->_service->getByPrimaryKey($id);
}
public function getEditBar(){
$editArr = $this->getEditArr();
$str = '';
if($this->_param[$this->_primaryKey]){
$str = <<<EOF
<input type="hidden" value="{$this->_param[$this->_primaryKey]}" size="30" name="{$this->_editFormData}[{$this->_primaryKey}]" class="textInput ">
EOF;
}
foreach($editArr as $column){
$name = $column['name'];
$require = $column['require'] ? 'required' : '';
$label = $column['label'] ? $column['label'] : $this->_one->getAttributeLabel($name);
$display = isset($column['display']) ? $column['display'] : '';
if(empty($display)){
$display = ['type' => 'inputString'];
}
//var_dump($this->_one['id']);
$value = $this->_one[$name] ? $this->_one[$name] : $column['default'];
$display_type = isset($display['type']) ? $display['type'] : 'inputString';
if($display_type == 'inputString'){
$str .=<<<EOF
<p>
<label>{$label}</label>
<input type="text" value="{$value}" size="30" name="{$this->_editFormData}[{$name}]" class="textInput {$require} ">
</p>
EOF;
}else if($display_type == 'inputDate'){
$valueData = $value ? date("Y-m-d",strtotime($value)) : '';
$str .=<<<EOF
<p>
<label>{$label}</label>
<input type="text" value="{$valueData}" size="30" name="{$this->_editFormData}[{$name}]" class="date textInput {$require} ">
</p>
EOF;
}else if($display_type == 'inputEmail'){
$str .=<<<EOF
<p>
<label>{$label}</label>
<input type="text" value="{$value}" size="30" name="{$this->_editFormData}[{$name}]" class="email textInput {$require} ">
</p>
EOF;
}else if($display_type == 'inputPassword'){
$str .=<<<EOF
<p>
<label>{$label}</label>
<input type="password" value="" size="30" name="{$this->_editFormData}[{$name}]" class=" textInput {$require} ">
</p>
EOF;
}else if($display_type == 'select'){
$data = isset($display['data']) ? $display['data'] : '';
//var_dump($data);
//echo $value;
$select_str = '';
if(is_array($data)){
$select_str .= <<<EOF
<select class="combox {$require}" name="{$this->_editFormData}[{$name}]" >
EOF;
$select_str .='<option value="">'.$label.'</option>';
foreach($data as $k => $v){
if($value == $k){
//echo $value."#".$k;
$select_str .='<option selected="selected" value="'.$k.'">'.$v.'</option>';
}else{
$select_str .='<option value="'.$k.'">'.$v.'</option>';
}
}
$select_str .= '</select>';
}
$str .=<<<EOF
<p>
<label>{$label}</label>
{$select_str}
</p>
EOF;
}else if($display_type == 'textarea'){
$rows = isset($display['rows']) ? $display['rows'] : 15;
$cols = isset($display['cols']) ? $display['cols'] : 110;
$this->_textareas .= <<<EOF
<fieldset id="fieldset_table_qbe">
<legend style="color:#cc0000">{$label}</legend>
<div>
<textarea class="editor" name="{$this->_editFormData}[{$name}]" rows="{$rows}" cols="{$cols}" name="{$this->_editFormData}[{$name}]" >{$value}</textarea>
</div>
</fieldset>
EOF;
}
}
return $str;
}
}
\ No newline at end of file
<?php
namespace fecshop\app\appadmin\modules\Cms;
use Yii;
use yii\helpers\Url;
use fecadmin\FecadminbaseController;
class CmsController extends FecadminbaseController
{
public function getViewPath()
{
return Yii::getAlias('@fecshop/app/appadmin/modules/Cms/views') . DIRECTORY_SEPARATOR . $this->id;
}
}
?>
\ No newline at end of file
<?php
namespace fecshop\app\appadmin\modules\Cms;
use Yii;
class Module extends \fec\AdminModule
{
public function init()
{
# 以下代码必须指定
$this->controllerNamespace = __NAMESPACE__ . '\\controllers';
$this->_currentDir = __DIR__ ;
$this->_currentNameSpace = __NAMESPACE__;
# 指定默认的man文件
$this->layout = "/main_ajax.php";
parent::init();
}
}
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appadmin\modules\cms\block\article;
use Yii;
use fecshop\app\appadmin\modules\AppadminbaseBlock;
use fec\helpers\CUrl;
use fecshop\app\appadmin\interfaces\base\AppadminbaseBlockInterface;
/**
* block cms\article
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Index extends AppadminbaseBlock implements AppadminbaseBlockInterface
{
/**
* init param function ,execute in construct
*/
public function init(){
/**
* edit data url
*/
$this->_editUrl = CUrl::getUrl("cms/article/manageredit");
/**
* delete data url
*/
$this->_deleteUrl = CUrl::getUrl("cms/article/managerdelete");
/**
* service component, data provider
*/
$this->_service = Yii::$app->cms->article;
parent::init();
}
public function getLastData(){
# hidden section ,that storage page info
$pagerForm = $this->getPagerForm();
# search section
$searchBar = $this->getSearchBar();
# edit button, delete button,
$editBar = $this->getEditBar();
# table head
$thead = $this->getTableThead();
# table body
$tbody = $this->getTableTbody();
# paging section
$toolBar = $this->getToolBar($this->_param['numCount'],$this->_param['pageNum'],$this->_param['numPerPage']);
return [
'pagerForm' => $pagerForm,
'searchBar' => $searchBar,
'editBar' => $editBar,
'thead' => $thead,
'tbody' => $tbody,
'toolBar' => $toolBar,
];
}
/**
* get search bar Arr config
*/
public function getSearchArr(){
$data = [
[ # selecit的Int 类型
'type'=>'select',
'title'=>'状态',
'name'=>'content',
'columns_type' =>'int', # int使用标准匹配, string使用模糊查询
'value'=> [ # select 类型的值
1=>'激活',
2=>'关闭',
],
],
[ # 字符串类型
'type'=>'inputtext',
'title'=>'标题',
'name'=>'title' ,
'columns_type' =>'string'
],
[ # 时间区间类型搜索
'type'=>'inputdatefilter',
'name'=> 'created_at',
'columns_type' =>'datetime',
'value'=>[
'gte'=>'用户创建时间开始',
'lt' =>'用户创建时间结束',
]
],
];
return $data;
}
/**
* config function ,return table columns config.
*
*/
public function getTableFieldArr(){
$table_th_bar = [
[
'orderField' => $this->_primaryKey,
'label' => 'ID',
'width' => '110',
'align' => 'center',
],
[
'orderField' => 'title',
'label' => '标题',
'width' => '110',
'align' => 'center',
],
[
'orderField' => 'created_user_id',
'label' => '创建人',
'width' => '110',
'align' => 'center',
],
[
'orderField' => 'created_at',
'label' => '创建时间',
'width' => '110',
'align' => 'center',
],
[
'orderField' => 'updated_at',
'label' => '更新时间',
'width' => '110',
'align' => 'center',
],
];
return $table_th_bar ;
}
/**
* rewrite parent getTableTbodyHtml($data)
*/
public function getTableTbodyHtml($data){
$fileds = $this->getTableFieldArr();
$str .= '';
$csrfString = \fec\helpers\CRequest::getCsrfString();
$user_ids = [];
foreach($data as $one){
$user_ids[]=$one['created_user_id'];
}
$users = Yii::$app->adminUser->getIdAndNameArrByIds($user_ids);
foreach($data as $one){
$str .= '<tr target="sid_user" rel="'.$one[$this->_primaryKey].'">';
$str .= '<td><input name="'.$this->_primaryKey.'s" value="'.$one[$this->_primaryKey].'" type="checkbox"></td>';
foreach($fileds as $field){
$orderField = $field['orderField'];
$display = $field['display'];
$val = $one[$orderField];
if($orderField == 'created_user_id'){
$val = isset($users[$val]) ? $users[$val] : $val;
$str .= '<td>'.$val.'</td>';
continue;
}
if($val){
if(isset($field['display']) && !empty($field['display'])){
$display = $field['display'];
$val = $display[$val] ? $display[$val] : $val;
}
if(isset($field['convert']) && !empty($field['convert'])){
$convert = $field['convert'];
foreach($convert as $origin =>$to){
if(strstr($origin,'mongodate')){
if(isset($val->sec)){
$timestramp = $val->sec;
if($to == 'date'){
$val = date('Y-m-d',$timestramp);
}else if($to == 'datetime'){
$val = date('Y-m-d H:i:s',$timestramp);
}else if($to == 'int'){
$val = $timestramp;
}
}
}else if(strstr($origin,'date')){
if($to == 'date'){
$val = date('Y-m-d',strtotime($val));
}else if($to == 'datetime'){
$val = date('Y-m-d H:i:s',strtotime($val));
}else if($to == 'int'){
$val = strtotime($val);
}
}else if($origin == 'int'){
if($to == 'date'){
$val = date('Y-m-d',$val);
}else if($to == 'datetime'){
$val = date('Y-m-d H:i:s',$val);
}else if($to == 'int'){
$val = $val;
}
}else if($origin == 'string'){
if($to == 'img'){
$t_width = isset($field['img_width']) ? $field['img_width'] : '100';
$t_height = isset($field['img_height']) ? $field['img_height'] : '100';
$val = '<img style="width:'.$t_width.'px;height:'.$t_height.'px" src="'.$val.'" />';;
}
}
}
}
}
$str .= '<td>'.$val.'</td>';
}
$str .= '<td>
<a title="编辑" target="dialog" class="btnEdit" mask="true" drawable="true" width="1000" height="580" href="'.$this->_editUrl.'?'.$this->_primaryKey.'='.$one[$this->_primaryKey].'" >编辑</a>
<a title="删除" target="ajaxTodo" href="'.$this->_deleteUrl.'?'.$csrfString.'&'.$this->_primaryKey.'='.$one[$this->_primaryKey].'" class="btnDel">删除</a>
</td>';
$str .= '</tr>';
}
return $str ;
}
}
\ No newline at end of file
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appadmin\modules\cms\block\article;
use Yii;
use fecshop\app\appadmin\modules\AppadminbaseBlockEdit;
use fec\helpers\CUrl;
use fec\helpers\CRequest;
use fecshop\app\appadmin\interfaces\base\AppadminbaseBlockEditInterface;
/**
* block cms\article
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Manageredit extends AppadminbaseBlockEdit implements AppadminbaseBlockEditInterface
{
public $_saveUrl;
public function init(){
$this->_saveUrl = CUrl::getUrl('cms/article/managereditsave');
parent::init();
}
# 传递给前端的数据 显示编辑form
public function getLastData(){
return [
'editBar' => $this->getEditBar(),
'textareas' => $this->_textareas,
'saveUrl' => $this->_saveUrl,
];
}
public function setService(){
$this->_service = Yii::$app->cms->article;
}
public function getEditArr(){
return [
[
'label'=>'标题',
'name'=>'title',
'display'=>[
'type' => 'inputString',
],
'require' => 1,
],
[
'label'=>'Url Key',
'name'=>'url_key',
'display'=>[
'type' => 'inputString',
],
'require' => 0,
],
[
'label'=>'Meta Keywords',
'name'=>'meta_keywords',
'display'=>[
'type' => 'inputString',
],
'require' => 0,
],
[
'label'=>'Meta Description',
'name'=>'meta_description',
'display'=>[
'type' => 'textarea',
'rows' => 7,
'cols' => 110,
],
'require' => 0,
],
[
'label'=>'Content',
'name'=>'content',
'display'=>[
'type' => 'textarea',
'rows' => 14,
'cols' => 110,
],
'require' => 0,
],
[
'label'=>'用户状态',
'name'=>'status',
'display'=>[
'type' => 'select',
'data' => [
1 => '激活',
2 => '关闭',
]
],
'require' => 1,
'default' => 1,
],
];
}
/**
* save article data, get rewrite url and save to article url key.
*/
public function save(){
$request_param = CRequest::param();
$this->_param = $request_param[$this->_editFormData];
$this->_service->save($this->_param,'cms/article/index');
$errors = Yii::$app->helper->errors->get();
if(!$errors ){
echo json_encode(array(
"statusCode"=>"200",
"message"=>"save success",
));
exit;
}else{
echo json_encode(array(
"statusCode"=>"300",
"message"=>$errors,
));
exit;
}
}
# 批量删除
public function delete(){
$ids = '';
if($id = CRequest::param($this->_primaryKey)){
$ids = $id;
}else if($ids = CRequest::param($this->_primaryKey.'s')){
$ids = explode(',',$ids);
}
$this->_service->remove($ids);
$errors = Yii::$app->helper->errors->get();
if(!$errors ){
echo json_encode(array(
"statusCode"=>"200",
"message"=>"remove data success",
));
exit;
}else{
echo json_encode(array(
"statusCode"=>"300",
"message"=>$errors,
));
exit;
}
}
}
\ No newline at end of file
<?php
namespace fecshop\app\appadmin\modules\Cms\controllers;
use Yii;
use yii\helpers\Url;
use fecshop\app\appadmin\modules\Cms\CmsController;
/**
* Site controller
*/
class ArticleController extends CmsController
{
public function actionIndex()
{
$data = $this->getBlock()->getLastData();
return $this->render($this->action->id,$data);
}
public function actionManageredit()
{
$data = $this->getBlock()->getLastData();
return $this->render($this->action->id,$data);
}
public function actionManagereditsave()
{
$data = $this->getBlock("manageredit")->save();
}
public function actionManagerdelete()
{
$this->getBlock("manageredit")->delete();
}
}
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
use fec\helpers\CRequest;
/**
* Breadcrumbs services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
?>
<form id="pagerForm" method="post" action="<?= \fec\helpers\CUrl::getCurrentUrl(); ?>">
<?= CRequest::getCsrfInputHtml(); ?>
<?= $pagerForm; ?>
</form>
<div class="pageHeader">
<form rel="pagerForm" onsubmit="return navTabSearch(this);" action="<?= \fec\helpers\CUrl::getCurrentUrl(); ?>" method="post">
<?php echo CRequest::getCsrfInputHtml(); ?>
<div class="searchBar">
<?php echo $searchBar; ?>
</div>
</form>
</div>
<div class="pageContent">
<div class="panelBar">
<?= $editBar; ?>
</div>
<div class="panelBar">
<?= $toolBar; ?>
</div>
<table class="table" width="100%" layoutH="138">
<?= $thead; ?>
<tbody>
<?= $tbody; ?>
</tbody>
</table>
</div>
<?php
use yii\helpers\Html;
use fec\helpers\CRequest;
use fecadmin\models\AdminRole;
?>
<style>
.checker{float:left;}
.dialog .pageContent {background:none;}
.dialog .pageContent .pageFormContent{background:none;}
</style>
<div class="pageContent">
<form method="post" action="<?= $saveUrl ?>" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDoneCloseAndReflush);">
<?php echo CRequest::getCsrfInputHtml(); ?>
<div layouth="56" class="pageFormContent" style="height: 240px; overflow: auto;">
<input type="hidden" value="<?= $product_id; ?>" size="30" name="product_id" class="textInput ">
<fieldset id="fieldset_table_qbe">
<legend style="color:#cc0000">编辑信息</legend>
<div>
<?= $editBar; ?>
</div>
</fieldset>
<?= $textareas ?>
</div>
<div class="formBar">
<ul>
<!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
<li><div class="buttonActive"><div class="buttonContent"><button onclick="func('accept')" value="accept" name="accept" type="submit">保存</button></div></div></li>
<li>
<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
</li>
</ul>
</div>
</form>
</div>
<?php
# 本文件在app/web/index.php 处引入。
# 本文件在app/web/index.php 处引入。
#
# fecshop - appfront 的核心模块
# fecshop - appfront 的核心模块
$modules = [];
foreach (glob(__DIR__ . '/modules/*.php') as $filename){
$modules = array_merge($modules,require($filename));
}
# 此处也可以重写fecshop的组件。供调用。
# 此处也可以重写fecshop的组件。供调用。
return [
'modules'=>$modules,
/* only config in front web */
......@@ -16,4 +16,22 @@ return [
'appfrontBaseTheme' => '@fecshop/app/appfront/theme/base/front',
'appfrontBaseLayoutName'=> 'main.php',
],
# language config.
'components' => [
'i18n' => [
'translations' => [
'appfront' => [
//'class' => 'yii\i18n\PhpMessageSource',
'class' => 'fecshop\yii\i18n\PhpMessageSource',
'basePath' => [
'@fecshop/app/appfront/languages',
'@appfront/languages',
],
'sourceLanguage' => 'en_US', # 如果 en_US 也想翻译,那么可以改成en_XX。
],
],
],
],
];
<?php
return [
'fecshop' => 'de_DE app fecshop',
];
\ No newline at end of file
<?php
return [
'fecshop' => 'en_US app fecshop',
];
\ No newline at end of file
<?php
return [
'fecshop' => 'es_ES app fecshop',
];
\ No newline at end of file
<?php
return [
'fecshop' => 'fr_FR app fecshop',
];
\ No newline at end of file
<?php
return [
'fecshop' => 'it_IT app fecshop',
];
\ No newline at end of file
<?php
return [
'fecshop' => 'nl_NL app fecshop',
];
\ No newline at end of file
<?php
return [
'fecshop' => 'pt_PT app fecshop',
];
\ No newline at end of file
<?php
return [
'fecshop' => 'ru_RU app fecshop',
];
\ No newline at end of file
<?php
return [
'fecshop' => 'zh_CN app fecshop',
];
\ No newline at end of file
......@@ -4,6 +4,7 @@ use Yii;
use fec\helpers\CConfig;
use fec\controllers\FecController;
use yii\base\InvalidValueException;
# use fecshop\app\appfront\modules\AppfrontController;
class AppfrontController extends FecController
{
public $blockNamespace;
......@@ -19,6 +20,10 @@ class AppfrontController extends FecController
if(!Yii::$app->page->theme->layoutFile){
Yii::$app->page->theme->layoutFile = CConfig::param('appfrontBaseLayoutName');
}
/**
* set i18n translate category.
*/
Yii::$app->page->translate->category = 'appfront';
}
/**
......
<?php
/*
* 存放 一些基本的非数据库数据 如 html
* 都是数组
*/
namespace fecshop\app\appfront\modules\cms\block\article;
use Yii;
use fec\helpers\CModule;
use fec\helpers\CRequest;
class Index {
protected $_artile;
public function getLastData(){
echo Yii::$app->page->translate->__('fecshop,{username}', ['username' => 'terry']);
$this->initHead();
# change current layout File.
//Yii::$app->page->theme->layoutFile = 'home.php';
return [
'title' => $this->_artile['title'],
'content' => $this->_artile['content'],
'created_at' => $this->_artile['created_at'],
];
}
public function initHead(){
$primaryKey = Yii::$app->cms->article->getPrimaryKey();
$primaryVal = CRequest::param($primaryKey);
$article = Yii::$app->cms->article->getByPrimaryKey($primaryVal);
$this->_artile = $article ;
Yii::$app->view->registerMetaTag([
'name' => 'keywords',
'content' => $article['meta_keywords'],
]);
Yii::$app->view->registerMetaTag([
'name' => 'description',
'content' => $article['meta_description'],
]);
Yii::$app->view->title = $article['title'];
}
}
<?php
namespace fecshop\app\appfront\modules\Cms\controllers;
use Yii;
use fec\helpers\CModule;
use fec\helpers\CRequest;
use fecshop\app\appfront\modules\AppfrontController;
class ArticleController extends AppfrontController
{
public function init(){
parent::init();
}
# վϢ
public function actionIndex()
{
//$primaryKey = Yii::$app->cms->article->getPrimaryKey();
//$article = Yii::$app->cms->article->getByPrimaryKey(CRequest::param($primaryKey));
//var_dump($article);
//echo 'article';
$data = $this->getBlock()->getLastData();
return $this->render($this->action->id,$data);
}
public function actionChangecurrency(){
$currency = \fec\helpers\CRequest::param('currency');
Yii::$app->page->currency->setCurrentCurrency($currency);
}
}
......@@ -6,7 +6,6 @@ use fecshop\app\appfront\modules\AppfrontController;
class HomeController extends AppfrontController
{
public function init(){
\Yii::$app->systemhelper->controllerNameSpace = __namespace__;
parent::init();
}
# վϢ
......@@ -19,12 +18,12 @@ class HomeController extends AppfrontController
//echo Yii::$app->cms->article->save($one);
//exit;
$r = Yii::$app->cms->article->remove([4,555]);
if(!$r)
var_dump(Yii::$app->helper->errors->get());
exit;
$coll = Yii::$app->cms->article->coll();
var_dump($coll);
//$r = Yii::$app->cms->article->remove([4,555]);
//if(!$r)
// var_dump(Yii::$app->helper->errors->get());
//exit;
//$coll = Yii::$app->cms->article->coll();
//var_dump($coll);
# change current layout File.
//Yii::$app->page->theme->layoutFile = 'home.php';
$this->getBlock()->getLastData();
......
<h1><?= $title ?></h1>
<div>
<?= $content ?>
</div>
\ No newline at end of file
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
return [
'adminUser' => [
'class' => 'fecshop\services\AdminUser',
],
];
\ No newline at end of file
......@@ -9,11 +9,12 @@
return [
'cms' => [
'class' => 'fecshop\services\Cms',
'storage' => 'mysqldb', # mysqldb or mongodb.
# ӷ
'childService' => [
'article' => [
'class' => 'fecshop\services\cms\Article',
'class' => 'fecshop\services\cms\Article',
'storage' => 'mysqldb', # mysqldb or mongodb.
],
],
],
......
......@@ -19,6 +19,9 @@ return [
'ifAddHomeUrl' => true, # default true, if set false, home will not add url (a).
//'intervalSymbol'=> ' >> ' # default value:' > '
],
'translate' => [
'class' => 'fecshop\services\page\Translate',
],
'asset' => [
'class' => 'fecshop\services\page\Asset',
......
......@@ -8,7 +8,8 @@
*/
return [
'url' => [
'class' => 'fecshop\services\Url',
'class' => 'fecshop\services\Url',
'storage' => 'mongodb', # 'mongodb or mysqldb'
'randomCount'=> 8, # if url key is exist in url write table , add a random string behide the url key, this param is define random String length
],
];
\ No newline at end of file
......@@ -27,9 +27,11 @@ class UrlRewrite extends ActiveRecord
public function attributes()
{
return [
'_id', 'type',
'custom_url',
'yii_url', 'status'
'_id',
'type',
'custom_url_key',
'origin_url',
'status'
];
}
}
\ No newline at end of file
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\models\mysqldb;
use Yii;
use yii\db\ActiveRecord;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class UrlRewrite extends ActiveRecord
{
public static function tableName()
{
return 'url_rewrite';
}
}
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
/**
* AdminUser services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class AdminUser extends Service
{
#Yii::$app->adminUser->getIdAndNameArrByIds($ids)
public function getIdAndNameArrByIds($ids){
$user_coll = \fecadmin\models\AdminUser::find()->asArray()->select(['id','username'])->where([
'in','id',$ids
])->all();
$users = [];
foreach($user_coll as $one){
$users[$one['id']] = $one['username'];
}
return $users;
}
}
\ No newline at end of file
......@@ -55,39 +55,46 @@ class Request extends \yii\web\Request
* get module request url by db ;
*/
protected function getRewriteUri($requestUri){
$urlPath = '';
$baseUrl = $this->getBaseUrl();
$requestUriRelative = $requestUri;
if($baseUrl){
$requestUriRelative = substr($requestUriRelative, strlen($baseUrl));
}
//echo $requestUriRelative;exit;
$urlKey = '';
$urlParam = '';
$urlParamSuffix = '';
if(strstr($requestUri,"#")){
list($urlNoSuffix,$urlParamSuffix)= explode("#",$requestUri);
if(strstr($requestUriRelative,"#")){
list($urlNoSuffix,$urlParamSuffix)= explode("#",$requestUriRelative);
if(strstr($urlNoSuffix,"?")){
list($urlPath,$urlParam)= explode("?",$urlNoSuffix);
list($urlKey,$urlParam)= explode("?",$urlNoSuffix);
}
}else if(strstr($requestUri,"?")){
list($urlPath,$urlParam)= explode("?",$requestUri);
}else if(strstr($requestUriRelative,"?")){
list($urlKey,$urlParam)= explode("?",$requestUriRelative);
}else{
$urlPath = $requestUri;
$urlKey = $requestUriRelative;
}
if($urlParamSuffix){
$urlParamSuffix = '#'.$urlParamSuffix;
}
if($yiiUrlPath = $this->getYiiUrl($urlPath)){
if(strstr($yiiUrlPath,'?')){
if($originUrlPath = Yii::$app->url->getOriginUrl($urlKey)){
if(strstr($originUrlPath,'?')){
if($urlParam){
$url = $yiiUrlPath.'&'.$urlParam.$urlParamSuffix;
$url = $originUrlPath.'&'.$urlParam.$urlParamSuffix;
}else{
$url = $yiiUrlPath.$urlParamSuffix;
$url = $originUrlPath.$urlParamSuffix;
}
$this->setRequestParam($yiiUrlPath);
$this->setRequestParam($originUrlPath);
}else{
if($urlParam){
$url = $yiiUrlPath.'?'.$urlParam.$urlParamSuffix;
$url = $originUrlPath.'?'.$urlParam.$urlParamSuffix;
}else{
$url = $yiiUrlPath.$urlParamSuffix;
$url = $originUrlPath.$urlParamSuffix;
}
}
return $url;
return $baseUrl.$url;
}else{
return $requestUri;
}
......@@ -98,8 +105,8 @@ class Request extends \yii\web\Request
* after get urlPath from db, if urlPath has get param ,
* set the param to $_GET
*/
public function setRequestParam($yiiUrlPath){
$arr = explode("?",$yiiUrlPath);
public function setRequestParam($originUrlPath){
$arr = explode("?",$originUrlPath);
$yiiUrlParam = $arr[1];
$arr = explode("&",$yiiUrlParam);
foreach($arr as $a){
......@@ -112,12 +119,12 @@ class Request extends \yii\web\Request
* mongodb url_rewrite collection columns: _id, type ,custom_url, yii_url,
* if selete date from UrlRewrite, return the yii url.
*/
protected function getYiiUrl($urlPath){
protected function getOriginUrl($urlKey){
$UrlData = UrlRewrite::find()->where([
'custom_url' => $urlPath,
'custom_url_key' => $urlKey,
])->asArray()->one();
if($UrlData['custom_url']){
return $UrlData['yii_url'];
if($UrlData['custom_url_key']){
return $UrlData['origin_url'];
}
return ;
}
......
......@@ -62,6 +62,7 @@ class Store extends Service implements BootstrapInterface
if(isset($store['language']) && !empty($store['language'])){
Yii::$app->store->currentLang = $store['language'];
Yii::$app->store->currentLangName = $store['languageName'];
Yii::$app->page->translate->setLanguage($store['language']);
}
if(isset($store['theme']) && !empty($store['theme'])){
Yii::$app->store->currentTheme = $store['theme'];
......
......@@ -11,7 +11,8 @@ use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use yii\base\BootstrapInterface;
use fecshop\models\mongodb\UrlRewrite;
use fecshop\models\mongodb\UrlRewrite as MongodbUrlRewrite;
use fecshop\models\mysqldb\UrlRewrite as MysqldbUrlRewrite;
use fec\helpers\CUrl;
/**
*
......@@ -24,35 +25,88 @@ class Url extends Service
protected $_secure;
protected $_http;
protected $_baseUrl;
protected $_origin_url;
public $storage = 'mysqldb';
public $randomCount = 8;
/**
* save custom url to mongodb collection url_rewrite
* @param $urlArr|Array, example:
* $urlArr = [
* 'custom_url' => '/xxxx.html',
* 'yii_url' => '/product/index?_id=32',
* ];
* @param $type|String.
* @param $str|String, example: fashion handbag women
* @param $originUrl|String , origin url ,example: /cms/home/index?id=5
* @param $originUrlKey|String,origin url key, it can be empty ,or generate by system , or custom url key.
* @param $type|String, url rewrite type.
* @return rewrite Key.
*/
public function saveCustomUrl($urlArr,$type='system'){
$data = UrlRewrite::find()->where([
'custom_url' => $urlArr['custom_url'],
])->asArray()->one();
if(isset($data['custom_url'])){
throw new InvalidValueException('custom_url is exist in mongodb collection url_rewrite,which _id is:'.$data['_id']);
public function saveRewriteUrlKeyByStr($str,$originUrl,$originUrlKey,$type='system'){
$originUrl = $originUrl ? '/'.trim($originUrl,'/') : '';
$originUrlKey = $originUrlKey ? '/'.trim($originUrlKey,'/') : '';
if($originUrlKey){
/**
* if originUrlKey and originUrl is exist in url rewrite collectons.
*/
$model = $this->find();
$data = $model->where([
'custom_url_key' => $originUrlKey,
'origin_url' => $originUrl,
])->asArray()->one();
if(isset($data['custom_url_key'])){
return $originUrlKey;
}
}
if($originUrlKey){
$urlKey = $this->generateUrlByName($originUrlKey);
}else{
$arr = [
'type' => $type,
'custom_url'=> $urlArr['custom_url'],
'yii_url' => $urlArr['yii_url'],
];
$UrlRewrite = UrlRewrite::getCollection();
$UrlRewrite->save($arr);
return true;
$urlKey = $this->generateUrlByName($str);
}
if(strlen($urlKey)<=1){
$urlKey .= $this->getRandom(5);
}
if(strlen($urlKey)<=2){
$urlKey .= '-'.$this->getRandom(5);
}
$urlKey = $this->getRewriteUrlKey($urlKey,$originUrl);
$UrlRewrite = $this->findOne([
'origin_url' => $originUrl
]);
if(!isset($UrlRewrite['origin_url'])){
$UrlRewrite = $this->newModel();
}
$UrlRewrite->type = $type;
$UrlRewrite->custom_url_key = $urlKey;
$UrlRewrite->origin_url = $originUrl;
$UrlRewrite->save($arr);
return $urlKey;
}
/**
* @property $url_key|String
* remove url rewrite data by $url_key,which is custom url key that saved in custom url modules,like articcle , product, category ,etc..
*/
public function removeRewriteUrlKey($url_key){
$model = $this->findOne([
'custom_url_key' => $url_key,
]);
if($model['custom_url_key']){
$model->delete();
}
}
/**
* @property $urlKey|String
* get $origin_url by $custom_url_key ,it is used for yii2 init,
* in (new fecshop\services\Request)->resolveRequestUri(), ## fecshop\services\Request is extend yii\web\Request
*/
public function getOriginUrl($urlKey){
$model = $this->find();
$UrlData = $model->where([
'custom_url_key' => $urlKey,
])->asArray()->one();
if($UrlData['custom_url_key']){
return $UrlData['origin_url'];
}
return ;
}
/**
* @property $path|String, for example about-us.html, fashion-handbag/women.html
......@@ -85,6 +139,40 @@ class Url extends Service
return Yii::$app->getHomeUrl();
}
protected function newModel(){
if($this->storage == 'mysqldb'){
return new MysqldbUrlRewrite;
}else if($this->storage == 'mongodb'){
return new MongodbUrlRewrite;
}
}
protected function find(){
if($this->storage == 'mysqldb'){
return MysqldbUrlRewrite::find();
}else if($this->storage == 'mongodb'){
return MongodbUrlRewrite::find();
}
}
protected function findOne($where){
if($this->storage == 'mysqldb'){
$model = MysqldbUrlRewrite::findOne($where);
}else if($this->storage == 'mongodb'){
$model = MongodbUrlRewrite::findOne($where);
}
return $model;
}
/**
* check current url type is http or https. https is secure url type.
*/
protected function secure(){
if($this->_secure === null){
$this->_secure = isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'], 'on') === 0 || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0;
......@@ -92,4 +180,61 @@ class Url extends Service
return $this->_secure;
}
/**
* get rewrite url key.
*/
protected function getRewriteUrlKey($urlKey,$originUrl){
$model = $this->find();
$data = $model->where([
'custom_url_key' => $urlKey,
])->andWhere(['<>','origin_url',$originUrl])
->asArray()->one();
if(isset($data['custom_url_key'])){
$urlKey = $this->getRandomUrlKey($urlKey);
return $this->getRewriteUrlKey($urlKey,$originUrl);
}else{
return $urlKey;
}
}
/**
* generate random string.
*/
protected function getRandom($length=''){
if(!$length ){
$length = $this->randomCount;
}
$str = null;
$strPol = "123456789";
$max = strlen($strPol)-1;
for($i=0;$i<$length;$i++){
$str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
}
return $str;
}
/**
* if url key is exist in url_rewrite table ,Behind url add some random string
*/
protected function getRandomUrlKey($url){
if($this->_origin_url){
$randomStr = $this->getRandom();
return $this->_origin_url.'-'.$randomStr;
}
}
/**
* clear character that can not use for url.
*/
protected function generateUrlByName($name){
$url = iconv('UTF-8', 'ASCII//TRANSLIT', $name);
$url = preg_replace("{[^a-zA-Z0-9_.| -]}", '', $url);
$url = strtolower(trim($url, '-'));
$url = preg_replace("{[_| -]+}", '-', $url);
$url = '/'.trim($url,'/');
$this->_origin_url = $url;
return $url;
}
}
\ No newline at end of file
......@@ -22,32 +22,69 @@ use fecshop\services\cms\article\ArticleMongodb;
*/
class Article extends ChildService
{
public $storage = 'mongodb';
protected $_article;
public function init(){
if(Yii::$app->cms->storage == 'mongodb'){
if($this->storage == 'mongodb'){
$this->_article = new ArticleMongodb;
}else{
}else if($this->storage == 'mysqldb'){
$this->_article = new ArticleMysqldb;
}
}
public function getById($id){
return $this->_article->getById($id);
/**
* Get Url by article's url key.
*/
public function getUrl($urlKey){
return Yii::$app->url->getBaseUrl.'/'.$urlKey;
}
/**
* get artile's primary key.
*/
public function getPrimaryKey(){
return $this->_article->getPrimaryKey();
}
/**
* get artile model by primary key.
*/
public function getByPrimaryKey($primaryKey){
return $this->_article->getByPrimaryKey($primaryKey);
}
//public function getById($id){
// return $this->_article->getById($id);
//}
/**
* @property $filter|Array
* get artile collection by $filter
* example filter:
* [
* 'numPerPage' => 20,
* 'pageNum' => 1,
* 'orderBy' => ['_id' => SORT_DESC, 'sku' => SORT_ASC ],
* 'where' => [
* 'price' => [
* '?gt' => 1,
* '?lt' => 10,
* ],
* 'sku' => 'uk10001',
* ],
* 'asArray' => true,
* ]
*/
public function coll($filter=''){
return $this->_article->coll($filter);
}
/**
* @property $date|Array
* @property $one|Array , save one data .
* @property $originUrlKey|String , article origin url key.
* save $data to cms model,then,add url rewrite info to system service urlrewrite.
*/
public function save($one){
return $this->_article->save($one);
public function save($one,$originUrlKey){
return $this->_article->save($one,$originUrlKey);
}
public function remove($ids){
......
......@@ -10,8 +10,8 @@ namespace fecshop\services\cms\article;
interface ArticleInterface{
public function getById($id);
public function getByPrimaryKey($primaryKey);
public function coll($filter);
public function save($one);
public function save($one,$originUrlKey);
public function remove($ids);
}
\ No newline at end of file
......@@ -20,8 +20,18 @@ class ArticleMysqldb implements ArticleInterface
{
public $numPerPage = 20;
public function getById($id){
return Article::findOne($id);
public function getPrimaryKey(){
return 'id';
}
public function getByPrimaryKey($primaryKey){
if($primaryKey){
return Article::findOne($primaryKey);
}else{
return new Article;
}
}
/*
* example filter:
......@@ -42,42 +52,90 @@ class ArticleMysqldb implements ArticleInterface
public function coll($filter=''){
$query = Article::find();
return Yii::$app->helper->ar->getCollByFilter($query,$filter);
$query = Yii::$app->helper->ar->getCollByFilter($query,$filter);
return [
'coll' => $query->all(),
'count'=> $query->count(),
];
}
/**
* @property $one|Array
* save $data to cms model,then,add url rewrite info to system service urlrewrite.
*/
public function save($one){
$id = isset($one['id']) ? $one['id'] : '';
if($id){
$model = Article::findOne($id);
public function save($one,$originUrlKey){
$currentDateTime = \fec\helpers\CDate::getCurrentDateTime();
$primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : '';
if($primaryVal){
$model = Article::findOne($primaryVal);
if(!$model){
Yii::$app->helper->errors->add('article '.$this->getPrimaryKey().' is not exist');
return;
}
}else{
$model = new Article;
$model->created_at = $currentDateTime;
$model->created_user_id = \fec\helpers\CUser::getCurrentUserId();
}
$model->updated_at = $currentDateTime;
$saveStatus = Yii::$app->helper->ar->save($model,$one);
if(!$primaryVal){
$primaryVal = Yii::$app->db->getLastInsertID();
}
return Yii::$app->helper->ar->save($model,$one);
$originUrl = $originUrlKey.'?'.$this->getPrimaryKey() .'='. $primaryVal;
$originUrlKey = isset($one['url_key']) ? $one['url_key'] : '';
$urlKey = Yii::$app->url->saveRewriteUrlKeyByStr($one['title'],$originUrl,$originUrlKey);
$model->url_key = $urlKey;
$model->save();
return true;
}
public function remove($ids){
if(!$ids){
Yii::$app->helper->errors->add('remove id is empty');
return false;
}
if(is_array($ids) && !empty($ids)){
foreach($ids as $id){
$model = Article::findOne($id);
if($model->id){
$model->delete();
}else{
//throw new InvalidValueException("ID:$id is not exist.");
Yii::$app->helper->errors->add("article remove ,ID:$id is not exist.");
return false;
$innerTransaction = Yii::$app->db->beginTransaction();
try {
foreach($ids as $id){
$model = Article::findOne($id);
if($model->id){
$url_key = $model['url_key'];
Yii::$app->url->removeRewriteUrlKey($url_key);
$model->delete();
}else{
//throw new InvalidValueException("ID:$id is not exist.");
Yii::$app->helper->errors->add("Article Remove Errors:ID $id is not exist.");
$innerTransaction->rollBack();
return false;
}
}
$innerTransaction->commit();
} catch (Exception $e) {
Yii::$app->helper->errors->add("Article Remove Errors: transaction rollback");
$innerTransaction->rollBack();
return false;
}
}else{
$id = $ids;
$model = Article::findOne($id);
if($model->id){
$model->delete();
$innerTransaction = Yii::$app->db->beginTransaction();
try {
$url_key = $model['url_key'];
Yii::$app->url->removeRewriteUrlKey($url_key);
$model->delete();
$innerTransaction->commit();
} catch (Exception $e) {
Yii::$app->helper->errors->add("Article Remove Errors: transaction rollback");
$innerTransaction->rollBack();
}
}else{
Yii::$app->helper->errors->add("article remove ,ID:$id is not exist.");
Yii::$app->helper->errors->add("Article Remove Errors:ID:$id is not exist.");
return false;
}
}
......
......@@ -48,25 +48,46 @@ class AR extends ChildService
if($asArray)
$query->asArray();
if($where)
$query->where($where);
if($where){
if(is_array($where)){
$i = 0;
foreach($where as $w){
$i++;
if($i==1){
$query->where($w);
}else{
$query->andWhere($w);
}
}
}
}
$offset = ($pageNum -1 ) * $numPerPage;
$query->limit($numPerPage)->offset($offset);
if($orderBy)
$query->orderBy($orderBy);
return $query->all();
return $query;
}
public function save($model,$one){
if(!$model){
Yii::$app->helper->errors->add('ActiveRecord Save Error: $model is empty');
return;
}
$attributes = $model->attributes();
foreach($attributes as $attr){
if(isset($one[$attr])){
$model[$attr] = $one[$attr];
if(is_array($attributes) && !empty($attributes)){
foreach($attributes as $attr){
if(isset($one[$attr])){
$model[$attr] = $one[$attr];
}
}
return $model->save();
}else{
Yii::$app->helper->errors->add('$attribute is empty or is not array');
return;
}
return $model->save();
}
......
......@@ -20,7 +20,7 @@ use fecshop\services\ChildService;
*/
class Errors extends ChildService
{
protected $_errors ;
protected $_errors = false ;
public $status = true;
public function add($str){
......@@ -33,7 +33,12 @@ class Errors extends ChildService
}
public function get(){
return $this->_errors;
if($this->_errors){
$errors = $this->_errors;
$this->_errors = false;
return implode('|',$errors);
}
return false;
}
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\services\page;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Breadcrumbs services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Translate extends ChildService
{
/**
* current i18n category. it will set in controller init .
* example: fecshop\app\appfront\modules\AppfrontController
* code: Yii::$app->page->translate->category = 'appfront';
*/
public $category;
/**
* Yii::$app->page->translate->__('Hello, {username}!', ['username' => $username]);
*/
public function __($text,$arr=[]){
if(!$this->category){
return $text;
}else{
return Yii::t($this->category, $text ,$arr);
}
}
public function setLanguage($language){
Yii::$app->language = $language;
}
}
\ No newline at end of file
<?php
namespace fecshop\yii\i18n;
use Yii;
use yii\i18n\PhpMessageSource as YiiPhpMessageSource;
class PhpMessageSource extends YiiPhpMessageSource
{
protected function loadMessages($category, $language)
{
$messageFile = $this->getMessageFilePath($category, $language);
if(is_array($messageFile)){
foreach($messageFile as $messFile){
$messages = $this->loadMessagesFromFile($messFile);
$fallbackLanguage = substr($language, 0, 2);
$fallbackSourceLanguage = substr($this->sourceLanguage, 0, 2);
if ($language !== $fallbackLanguage) {
$messages = $this->loadFallbackMessages($category, $fallbackLanguage, $messages, $messFile);
} elseif ($language === $fallbackSourceLanguage) {
$messages = $this->loadFallbackMessages($category, $this->sourceLanguage, $messages, $messFile);
} else {
if ($messages === null) {
Yii::error("The message file for category '$category' does not exist: $messFile", __METHOD__);
}
}
}
return $messages;
}else{
$messages = $this->loadMessagesFromFile($messageFile);
$fallbackLanguage = substr($language, 0, 2);
$fallbackSourceLanguage = substr($this->sourceLanguage, 0, 2);
if ($language !== $fallbackLanguage) {
$messages = $this->loadFallbackMessages($category, $fallbackLanguage, $messages, $messageFile);
} elseif ($language === $fallbackSourceLanguage) {
$messages = $this->loadFallbackMessages($category, $this->sourceLanguage, $messages, $messageFile);
} else {
if ($messages === null) {
Yii::error("The message file for category '$category' does not exist: $messageFile", __METHOD__);
}
}
return (array) $messages;
}
}
/**
* The method is normally called by [[loadMessages]] to load the fallback messages for the language.
* Method tries to load the $category messages for the $fallbackLanguage and adds them to the $messages array.
*
* @param string $category the message category
* @param string $fallbackLanguage the target fallback language
* @param array $messages the array of previously loaded translation messages.
* The keys are original messages, and the values are the translated messages.
* @param string $originalMessageFile the path to the file with messages. Used to log an error message
* in case when no translations were found.
* @return array the loaded messages. The keys are original messages, and the values are the translated messages.
* @since 2.0.7
*/
protected function loadFallbackMessages($category, $fallbackLanguage, $messages, $originalMessageFile)
{
$fallbackMessageFile = $this->getMessageFilePath($category, $fallbackLanguage);
if(is_array($fallbackMessageFile)){
foreach($fallbackMessageFile as $file){
$fallbackMessages = $this->loadMessagesFromFile($file);
if (
$messages === null && $fallbackMessages === null
&& $fallbackLanguage !== $this->sourceLanguage
&& $fallbackLanguage !== substr($this->sourceLanguage, 0, 2)
) {
Yii::error("The message file for category '$category' does not exist: $originalMessageFile "
. "Fallback file does not exist as well: $file", __METHOD__);
} elseif (empty($messages)) {
return $fallbackMessages;
} elseif (!empty($fallbackMessages)) {
foreach ($fallbackMessages as $key => $value) {
if (!empty($value) && empty($messages[$key])) {
$messages[$key] = $fallbackMessages[$key];
}
}
}
return (array) $messages;
}
}else{
$fallbackMessages = $this->loadMessagesFromFile($fallbackMessageFile);
if (
$messages === null && $fallbackMessages === null
&& $fallbackLanguage !== $this->sourceLanguage
&& $fallbackLanguage !== substr($this->sourceLanguage, 0, 2)
) {
Yii::error("The message file for category '$category' does not exist: $originalMessageFile "
. "Fallback file does not exist as well: $fallbackMessageFile", __METHOD__);
} elseif (empty($messages)) {
return $fallbackMessages;
} elseif (!empty($fallbackMessages)) {
foreach ($fallbackMessages as $key => $value) {
if (!empty($value) && empty($messages[$key])) {
$messages[$key] = $fallbackMessages[$key];
}
}
}
return (array) $messages;
}
}
/**
* Returns message file path for the specified language and category.
*
* @param string $category the message category
* @param string $language the target language
* @return string path to message file
*/
protected function getMessageFilePath($category, $language)
{
if(is_array($this->basePath)){
$messageFiles = [];
foreach($this->basePath as $bp){
$messageFile = Yii::getAlias($bp) . "/$language/";
if (isset($this->fileMap[$category])) {
$messageFile .= $this->fileMap[$category];
} else {
$messageFile .= str_replace('\\', '/', $category) . '.php';
}
$messageFiles[] = $messageFile;
}
return $messageFiles;
}else{
$messageFile = Yii::getAlias($this->basePath) . "/$language/";
if (isset($this->fileMap[$category])) {
$messageFile .= $this->fileMap[$category];
} else {
$messageFile .= str_replace('\\', '/', $category) . '.php';
}
return $messageFile;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册