提交 7038e3e0 编写于 作者: T Terry

进一步优化重写机制:block层和models层

上级 1971354a
......@@ -86,4 +86,33 @@ class AppadminController extends FecadminbaseController
}
throw new InvalidValueException('layout file is not exist!');
}
public function getBlock($blockname=''){
$_currentNameSpace = \fec\helpers\CModule::param("_currentNameSpace");
//echo $_currentNameSpace;exit;
if(empty($_currentNameSpace)){
$message = "Modules Param '_currentNameSpace' is not set , you can set like fecadmin\\Module";
throw new \yii\web\HttpException(406,$message);
}
$modulesDir = "\\".$_currentNameSpace."\\block\\";
$url_key = \fec\helpers\CUrl::getUrlKey();
$url_key = trim($url_key,"/");
$url_key = substr($url_key,strpos($url_key,"/")+1 );
$url_key_arr = explode("/",$url_key);
if(!isset($url_key_arr[1])) $url_key_arr[1] = 'index';
if($blockname){
$url_key_arr[count($url_key_arr)-1] = ucfirst($blockname);
}else{
$url_key_arr[count($url_key_arr)-1] = ucfirst($url_key_arr[count($url_key_arr)-1]);
}
$block_space = implode("\\",$url_key_arr);
$blockFile = $modulesDir.$block_space;
//查找是否在rewriteMap中存在重写
$relativeFile = Yii::mapGetName($relativeFile);
//echo $blockFile;exit;
return new $blockFile;
}
}
......@@ -12,7 +12,7 @@ namespace fecshop\app\appadmin\modules\Catalog\block\productinfo;
use fec\helpers\CUrl;
use fecshop\app\appadmin\interfaces\base\AppadminbaseBlockInterface;
use fecshop\app\appadmin\modules\AppadminbaseBlock;
use fecshop\app\appadmin\modules\Catalog\helper\Product as ProductHelper;
//use fecshop\app\appadmin\modules\Catalog\helper\Product as ProductHelper;
use Yii;
/**
......@@ -23,12 +23,23 @@ use Yii;
class Index extends AppadminbaseBlock implements AppadminbaseBlockInterface
{
protected $_copyUrl;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_productHelperName = '\fecshop\app\appadmin\modules\Catalog\helper\Product';
protected $_productHelper;
/**
* init param function ,execute in construct.
*/
public function init()
{
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list($this->_productHelperName,$this->_productHelper) = Yii::mapGet($this->_productHelperName);
/*
* edit data url
*/
......@@ -82,14 +93,14 @@ class Index extends AppadminbaseBlock implements AppadminbaseBlockInterface
'title'=>'状态',
'name'=>'status',
'columns_type' =>'int', // int使用标准匹配, string使用模糊查询
'value'=> ProductHelper::getStatusArr(),
'value'=> $this->_productHelper::getStatusArr(),
],
[ // selecit的Int 类型
'type'=>'select',
'title'=>'库存状态',
'name'=>'is_in_stock',
'columns_type' =>'int', // int使用标准匹配, string使用模糊查询
'value'=> ProductHelper::getInStockArr(),
'value'=> $this->_productHelper::getInStockArr(),
],
[ // 字符串类型
'type' =>'inputtext',
......@@ -191,7 +202,7 @@ class Index extends AppadminbaseBlock implements AppadminbaseBlockInterface
'label' => '状态',
'width' => '50',
'align' => 'center',
'display' => ProductHelper::getStatusArr(),
'display' => $this->_productHelper::getStatusArr(),
],
[
......
......@@ -13,7 +13,7 @@ use fec\helpers\CRequest;
use fec\helpers\CUrl;
use fecshop\app\appadmin\interfaces\base\AppadminbaseBlockEditInterface;
use fecshop\app\appadmin\modules\AppadminbaseBlockEdit;
use fecshop\app\appadmin\modules\Catalog\block\productinfo\index\Attr;
//use fecshop\app\appadmin\modules\Catalog\block\productinfo\index\Attr;
use Yii;
/**
......@@ -26,9 +26,19 @@ class Manageredit extends AppadminbaseBlockEdit implements AppadminbaseBlockEdit
public $_saveUrl;
protected $_attr;
protected $_custom_option_list_str;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_attrBlockName = '\fecshop\app\appadmin\modules\Catalog\block\productinfo\index\Attr';
protected $_attrBlock;
public function init()
{
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
$this->_attrBlockName = Yii::mapGetName($this->_attrBlockName);
$this->_saveUrl = CUrl::getUrl('catalog/productinfo/managereditsave');
parent::init();
$product_id = $this->_param[$this->_primaryKey];
......@@ -38,7 +48,7 @@ class Manageredit extends AppadminbaseBlockEdit implements AppadminbaseBlockEdit
$this->_one['qty'] = $qty ;
}
$this->_attr = new Attr($this->_one);
$this->_attr = new $this->_attrBlockName($this->_one);
//$this->_param = $request_param[$this->_editFormData];
}
......
......@@ -10,7 +10,7 @@
namespace fecshop\app\appadmin\modules\Catalog\block\productinfo\index;
use fec\helpers\CRequest;
use fecshop\app\appadmin\modules\Catalog\helper\Product as ProductHelper;
//use fecshop\app\appadmin\modules\Catalog\helper\Product as ProductHelper;
use Yii;
/**
......@@ -22,9 +22,19 @@ class Attr
{
protected $_currentAttrGroup;
protected $_attrInfo;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_productHelperName = '\fecshop\app\appadmin\modules\Catalog\helper\Product';
protected $_productHelper;
public function __construct($one)
{
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list($this->_productHelperName,$this->_productHelper) = Yii::mapGet($this->_productHelperName);
$currentAttrGroup = CRequest::param('attr_group');
if ($currentAttrGroup) {
$this->_currentAttrGroup = $currentAttrGroup;
......@@ -165,7 +175,7 @@ class Attr
'name'=>'status',
'display'=>[
'type' => 'select',
'data' => ProductHelper::getStatusArr(),
'data' => $this->_productHelper::getStatusArr(),
],
'require' => 1,
'default' => 1,
......@@ -212,7 +222,7 @@ class Attr
'name'=>'is_in_stock',
'display'=>[
'type' => 'select',
'data' => ProductHelper::getInStockArr(),
'data' => $this->_productHelper::getInStockArr(),
],
'require' => 1,
'default' => 1,
......
......@@ -77,7 +77,9 @@ class AppapiController extends ActiveController
$relativeFile = '\\'.$this->blockNamespace;
$relativeFile .= '\\'.$this->id.'\\'.ucfirst($blockName);
//查找是否在rewriteMap中存在重写
$relativeFile = Yii::mapGetName($relativeFile);
return new $relativeFile();
}
}
......@@ -75,7 +75,9 @@ class AppfrontController extends FecController
$viewId = str_replace('/', '\\', $viewId);
$relativeFile = '\\'.$this->blockNamespace;
$relativeFile .= '\\'.$viewId.'\\'.ucfirst($blockName);
//查找是否在rewriteMap中存在重写
$relativeFile = Yii::mapGetName($relativeFile);
return new $relativeFile();
}
......
......@@ -9,7 +9,7 @@
namespace fecshop\app\appfront\modules\Catalog\block\product;
use fecshop\app\appfront\modules\Catalog\helpers\Review as ReviewHelper;
// use fecshop\app\appfront\modules\Catalog\helpers\Review as ReviewHelper;
use Yii;
/**
......@@ -32,7 +32,22 @@ class Index
protected $_image_thumbnails;
// 在产品详细页面,在产品描述部分显示的产品图片列表
protected $_image_detail;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_reviewHelperName = '\fecshop\app\appfront\modules\Catalog\helpers\Review';
protected $_reviewHelper;
public function __construct()
{
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list($this->_reviewHelperName,$this->_reviewHelper) = Yii::mapGet($this->_reviewHelperName);
}
public function getLastData()
{
$productImgSize = Yii::$app->controller->module->params['productImgSize'];
......@@ -41,8 +56,8 @@ class Index
Yii::$service->url->redirect404();
return;
}
ReviewHelper::initReviewConfig();
$ReviewAndStarCount = ReviewHelper::getReviewAndStarCount($this->_product);
$this->_reviewHelper::initReviewConfig();
$ReviewAndStarCount = $this->_reviewHelper::getReviewAndStarCount($this->_product);
list($review_count, $reviw_rate_star_average) = $ReviewAndStarCount;
$this->filterProductImg($this->_product['image']);
$groupAttr = Yii::$service->product->getGroupAttr($this->_product['attr_group']);
......
......@@ -9,7 +9,7 @@
namespace fecshop\app\appfront\modules\Catalog\block\product;
use fecshop\app\appfront\modules\Catalog\helpers\Review as ReviewHelper;
//use fecshop\app\appfront\modules\Catalog\helpers\Review as ReviewHelper;
use Yii;
/**
......@@ -22,11 +22,22 @@ class Review
public $spu;
public $filterBySpu = true;
public $filterOrderBy = 'review_date';
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_reviewHelperName = '\fecshop\app\appfront\modules\Catalog\helpers\Review';
protected $_reviewHelper;
public function __construct()
{
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list($this->_reviewHelperName,$this->_reviewHelper) = Yii::mapGet($this->_reviewHelperName);
// 初始化当前appfront的设置,覆盖service的初始设置。
ReviewHelper::initReviewConfig();
$this->_reviewHelper::initReviewConfig();
}
/**
* 得到当前spu下面的所有评论信息。
......
......@@ -9,7 +9,7 @@
namespace fecshop\app\appfront\modules\Catalog\block\reviewproduct;
use fecshop\app\appfront\modules\Catalog\helpers\Review as ReviewHelper;
//use fecshop\app\appfront\modules\Catalog\helpers\Review as ReviewHelper;
use Yii;
/**
......@@ -19,10 +19,20 @@ use Yii;
class Add
{
protected $_add_captcha;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_reviewHelperName = '\fecshop\app\appfront\modules\Catalog\helpers\Review';
protected $_reviewHelper;
public function __construct()
{
ReviewHelper::initReviewConfig();
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list($this->_reviewHelperName,$this->_reviewHelper) = Yii::mapGet($this->_reviewHelperName);
$this->_reviewHelper::initReviewConfig();
}
/**
* @return boolean , review页面是否开启验证码验证。
......
......@@ -9,7 +9,7 @@
namespace fecshop\app\appfront\modules\Catalog\block\reviewproduct;
use fecshop\app\appfront\modules\Catalog\helpers\Review as ReviewHelper;
//use fecshop\app\appfront\modules\Catalog\helpers\Review as ReviewHelper;
use Yii;
/**
......@@ -25,11 +25,20 @@ class Lists
public $_page = 'p';
public $numPerPage = 20;
public $pageNum;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_reviewHelperName = '\fecshop\app\appfront\modules\Catalog\helpers\Review';
protected $_reviewHelper;
public function __construct()
{
// 初始化服务
ReviewHelper::initReviewConfig();
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list($this->_reviewHelperName,$this->_reviewHelper) = Yii::mapGet($this->_reviewHelperName);
$this->_reviewHelper::initReviewConfig();
}
/**
* @property $countTotal | Int
......@@ -88,7 +97,7 @@ class Lists
$pageToolBar = $this->getProductPage($count);
$coll = $data['coll'];
$ReviewAndStarCount = ReviewHelper::getReviewAndStarCount($product);
$ReviewAndStarCount = $this->_reviewHelper::getReviewAndStarCount($product);
list($review_count, $reviw_rate_star_average) = $ReviewAndStarCount;
return [
......
......@@ -75,7 +75,9 @@ class AppfrontController extends FecController
$viewId = str_replace('/', '\\', $viewId);
$relativeFile = '\\'.$this->blockNamespace;
$relativeFile .= '\\'.$viewId.'\\'.ucfirst($blockName);
//查找是否在rewriteMap中存在重写
$relativeFile = Yii::mapGetName($relativeFile);
return new $relativeFile();
}
......
......@@ -9,7 +9,7 @@
namespace fecshop\app\apphtml5\modules\Catalog\block\product;
use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
//use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
use Yii;
/**
......@@ -32,7 +32,20 @@ class Index
protected $_image_thumbnails;
// 在产品详细页面,在产品描述部分显示的产品图片列表
protected $_image_detail;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_reviewHelperName = '\fecshop\app\apphtml5\modules\Catalog\helpers\Review';
protected $_reviewHelper;
public function __construct()
{
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list($this->_reviewHelperName,$this->_reviewHelper) = Yii::mapGet($this->_reviewHelperName);
}
public function getLastData()
{
$productImgSize = Yii::$app->controller->module->params['productImgSize'];
......@@ -41,8 +54,8 @@ class Index
Yii::$service->url->redirect404();
return;
}
ReviewHelper::initReviewConfig();
$ReviewAndStarCount = ReviewHelper::getReviewAndStarCount($this->_product);
$this->_reviewHelper::initReviewConfig();
$ReviewAndStarCount = $this->_reviewHelper::getReviewAndStarCount($this->_product);
list($review_count, $reviw_rate_star_average) = $ReviewAndStarCount;
$this->filterProductImg($this->_product['image']);
$groupAttr = Yii::$service->product->getGroupAttr($this->_product['attr_group']);
......
......@@ -9,7 +9,7 @@
namespace fecshop\app\apphtml5\modules\Catalog\block\product;
use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
//use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
use Yii;
/**
......@@ -22,12 +22,22 @@ class Review
public $spu;
public $filterBySpu = true;
public $filterOrderBy = 'review_date';
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_reviewHelperName = '\fecshop\app\apphtml5\modules\Catalog\helpers\Review';
protected $_reviewHelper;
public function __construct()
{
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list($this->_reviewHelperName,$this->_reviewHelper) = Yii::mapGet($this->_reviewHelperName);
// 初始化当前apphtml5的设置,覆盖service的初始设置。
ReviewHelper::initReviewConfig();
$this->_reviewHelper::initReviewConfig();
}
/**
* 得到当前spu下面的所有评论信息。
*/
......
......@@ -9,7 +9,7 @@
namespace fecshop\app\apphtml5\modules\Catalog\block\reviewproduct;
use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
//use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
use Yii;
/**
......@@ -19,11 +19,21 @@ use Yii;
class Add
{
protected $_add_captcha;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_reviewHelperName = '\fecshop\app\apphtml5\modules\Catalog\helpers\Review';
protected $_reviewHelper;
public function __construct()
{
ReviewHelper::initReviewConfig();
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list($this->_reviewHelperName,$this->_reviewHelper) = Yii::mapGet($this->_reviewHelperName);
$this->_reviewHelper::initReviewConfig();
}
/**
* @return boolean , review页面是否开启验证码验证。
*/
......
......@@ -9,7 +9,7 @@
namespace fecshop\app\apphtml5\modules\Catalog\block\reviewproduct;
use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
//use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
use Yii;
/**
......@@ -25,11 +25,20 @@ class Lists
public $_page = 'p';
public $numPerPage = 20;
public $pageNum;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected $_reviewHelperName = '\fecshop\app\apphtml5\modules\Catalog\helpers\Review';
protected $_reviewHelper;
public function __construct()
{
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list($this->_reviewHelperName,$this->_reviewHelper) = Yii::mapGet($this->_reviewHelperName);
// 初始化服务
ReviewHelper::initReviewConfig();
$this->_reviewHelper::initReviewConfig();
}
/**
* @property $countTotal | Int
......@@ -88,7 +97,7 @@ class Lists
$pageToolBar = $this->getProductPage($count);
$coll = $data['coll'];
$ReviewAndStarCount = ReviewHelper::getReviewAndStarCount($product);
$ReviewAndStarCount = $this->_reviewHelper::getReviewAndStarCount($product);
list($review_count, $reviw_rate_star_average) = $ReviewAndStarCount;
return [
......
......@@ -63,7 +63,9 @@ class AppserverController extends FecController
$viewId = str_replace('/', '\\', $viewId);
$relativeFile = '\\'.$this->blockNamespace;
$relativeFile .= '\\'.$viewId.'\\'.ucfirst($blockName);
//查找是否在rewriteMap中存在重写
$relativeFile = Yii::mapGetName($relativeFile);
return new $relativeFile();
}
......
......@@ -39,7 +39,9 @@ class ConsoleController extends FecController
$relativeFile = '\\'.$this->blockNamespace;
$relativeFile .= '\\'.$this->id.'\\'.ucfirst($blockName);
//查找是否在rewriteMap中存在重写
$relativeFile = Yii::mapGetName($relativeFile);
return new $relativeFile();
}
}
......@@ -9,7 +9,7 @@
namespace fecshop\services\category;
use fecshop\models\mongodb\Category;
//use fecshop\models\mongodb\Category;
use Yii;
/**
......@@ -19,7 +19,26 @@ use Yii;
class CategoryMongodb implements CategoryInterface
{
public $numPerPage = 20;
protected $_categoryModelName = '\fecshop\models\mongodb\Category';
protected $_categoryModel;
public function __construct(){
list($this->_categoryModelName,$this->_categoryModel) = Yii::mapGet($this->_categoryModelName);
}
/**
* 通过主键,得到Category对象。
*/
public function getByPrimaryKey($primaryKey)
{
if ($primaryKey) {
return $this->_categoryModel::findOne($primaryKey);
} else {
return new $this->_categoryModelName;
}
}
/**
* 返回主键。
*/
......@@ -31,25 +50,16 @@ class CategoryMongodb implements CategoryInterface
* 得到分类激活状态的值
*/
public function getCategoryEnableStatus(){
return Category::STATUS_ENABLE;
return $this->_categoryModel::STATUS_ENABLE;
}
/**
* 得到分类在menu中显示的状态值
*/
public function getCategoryMenuShowStatus(){
return Category::MENU_SHOW;
}
/**
* 通过主键,得到Category对象。
*/
public function getByPrimaryKey($primaryKey)
{
if ($primaryKey) {
return Category::findOne($primaryKey);
} else {
return new Category();
}
return $this->_categoryModel::MENU_SHOW;
}
/*
* example filter:
......@@ -67,7 +77,7 @@ class CategoryMongodb implements CategoryInterface
*/
public function coll($filter = '')
{
$query = Category::find();
$query = $this->_categoryModel::find();
$query = Yii::$service->helper->ar->getCollByFilter($query, $filter);
return [
......@@ -81,7 +91,7 @@ class CategoryMongodb implements CategoryInterface
*/
public function collCount($filter = '')
{
$query = Category::find();
$query = $this->_categoryModel::find();
$query = Yii::$service->helper->ar->getCollByFilter($query, $filter);
return $query->count();
......@@ -97,7 +107,7 @@ class CategoryMongodb implements CategoryInterface
$currentDateTime = \fec\helpers\CDate::getCurrentDateTime();
$primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : '';
if ($primaryVal) {
$model = Category::findOne($primaryVal);
$model = $this->_categoryModel::findOne($primaryVal);
if (!$model) {
Yii::$service->helper->errors->add('Category '.$this->getPrimaryKey().' is not exist');
......@@ -105,7 +115,7 @@ class CategoryMongodb implements CategoryInterface
}
$parent_id = $model['parent_id'];
} else {
$model = new Category();
$model = new $this->_categoryModelName;
$model->created_at = time();
$model->created_user_id = \fec\helpers\CUser::getCurrentUserId();
$primaryVal = new \MongoDB\BSON\ObjectId();
......@@ -116,7 +126,7 @@ class CategoryMongodb implements CategoryInterface
if ($parent_id === '0') {
$model['level'] = 1;
} else {
$parent_model = Category::findOne($parent_id);
$parent_model = $this->_categoryModel::findOne($parent_id);
if ($parent_level = $parent_model['level']) {
$model['level'] = $parent_level + 1;
}
......@@ -149,7 +159,7 @@ class CategoryMongodb implements CategoryInterface
return false;
}
$model = Category::findOne($id);
$model = $this->_categoryModel::findOne($id);
if (isset($model[$this->getPrimaryKey()]) && !empty($model[$this->getPrimaryKey()])) {
$url_key = $model['url_key'];
Yii::$service->url->removeRewriteUrlKey($url_key);
......@@ -166,7 +176,7 @@ class CategoryMongodb implements CategoryInterface
protected function removeChildCate($id)
{
$data = Category::find()->where(['parent_id'=>$id])->all();
$data = $this->_categoryModel::find()->where(['parent_id'=>$id])->all();
if (!empty($data)) {
foreach ($data as $one) {
$idVal = (string) $one['_id'];
......@@ -196,7 +206,7 @@ class CategoryMongodb implements CategoryInterface
} else {
$where = ['parent_id' => $rootCategoryId];
}
$categorys = Category::find()->asArray()->where($where)->all();
$categorys = $this->_categoryModel::find()->asArray()->where($where)->all();
//var_dump($categorys);exit;
$idKey = $this->getPrimaryKey();
if (!empty($categorys)) {
......@@ -219,7 +229,7 @@ class CategoryMongodb implements CategoryInterface
protected function hasChildCategory($idVal)
{
$one = Category::find()->asArray()->where(['parent_id'=>$idVal])->one();
$one = $this->_categoryModel::find()->asArray()->where(['parent_id'=>$idVal])->one();
if (!empty($one)) {
return true;
}
......@@ -237,7 +247,7 @@ class CategoryMongodb implements CategoryInterface
public function getAllParentInfo($parent_id)
{
if ($parent_id) {
$parentModel = Category::findOne($parent_id);
$parentModel = $this->_categoryModel::findOne($parent_id);
$parent_parent_id = $parentModel['parent_id'];
$parent_category = [];
if ($parent_parent_id !== '0') {
......@@ -262,7 +272,7 @@ class CategoryMongodb implements CategoryInterface
if ($parent_id === '0') {
return [];
}
$category = Category::find()->asArray()->where(['_id' => new \MongoDB\BSON\ObjectId($parent_id)])->one();
$category = $this->_categoryModel::find()->asArray()->where(['_id' => new \MongoDB\BSON\ObjectId($parent_id)])->one();
if (isset($category['_id']) && !empty($category['_id'])) {
$currentUrlKey = $category['url_key'];
$currentName = $category['name'];
......@@ -296,7 +306,7 @@ class CategoryMongodb implements CategoryInterface
{
$returnData = [];
$primaryKey = $this->getPrimaryKey();
$currentCategory = Category::findOne($category_id);
$currentCategory = $this->_categoryModel::findOne($category_id);
$currentUrlKey = $currentCategory['url_key'];
$currentName = $currentCategory['name'];
$currentId = (string) $currentCategory['_id'];
......@@ -327,7 +337,7 @@ class CategoryMongodb implements CategoryInterface
$_id = $category['_id'];
$name = $category['name'];
$url_key = $category['url_key'];
$cate = Category::find()->asArray()->where([
$cate = $this->_categoryModel::find()->asArray()->where([
'parent_id' => $_id,
])->all();
if (is_array($cate) && !empty($cate)) {
......@@ -355,7 +365,7 @@ class CategoryMongodb implements CategoryInterface
$category_id = $category['_id'];
$parent_id = $category['parent_id'];
if ($parent_id) {
$cate = Category::find()->asArray()->where([
$cate = $this->_categoryModel::find()->asArray()->where([
'parent_id' => $parent_id,
])->all();
//var_dump($cate);
......@@ -394,7 +404,7 @@ class CategoryMongodb implements CategoryInterface
protected function getChildCate($category_id)
{
//echo $category_id;
$data = Category::find()->asArray()->where([
$data = $this->_categoryModel::find()->asArray()->where([
'parent_id' => $category_id,
])->all();
$arr = [];
......
......@@ -15,6 +15,45 @@ require $dir.'/BaseYii.php';
class Yii extends \yii\BaseYii
{
public static $service;
/**
* rewriteMap , like:
* [
* '\fecshop\models\mongodb\Category' => '\appadmin\models\mongodb\Category'
* ]
*/
public static $rewriteMap;
/**
* @property $absoluteClassName | String , like: '\fecshop\app\appfront\modules\Cms\block\home\Index'
* @property $arguments | Array ,数组,里面的每一个子项就是用于实例化的一个参数,多少个子项,就代表有多个参数,用于对象的实例化。
* 通过$rewriteMap,查找是否存在重写,如果存在,则得到重写的className
* 然后返回 类名 和 对象
*/
public static function mapGet($absoluteClassName,$arguments = []){
$absoluteClassName = self::mapGetName($absoluteClassName);
if (!empty($arguments) && is_array($arguments)) {
$class = new ReflectionClass($absoluteClassName);
$absoluteOb = $class->newInstanceArgs($arguments);
/**
* 下面的 ...,是php的语法糖(只能php5.6以上,放弃),也就是把$paramArray数组里面的各个子项参数,
* 作为对象生成的参数,详细可以参看:https://segmentfault.com/q/1010000006789348
*/
//$absoluteOb = new $absoluteClassName(...$arguments);
} else {
$absoluteOb = new $absoluteClassName;
}
return [$absoluteClassName,$absoluteOb];
}
/**
* @property $absoluteClassName | String , like: '\fecshop\app\appfront\modules\Cms\block\home\Index'
* 通过$rewriteMap,查找是否存在重写,如果存在,则返回重写的className
*/
public static function mapGetName($absoluteClassName){
if(isset(self::$rewriteMap[$absoluteClassName]) && self::$rewriteMap[$absoluteClassName]){
$absoluteClassName = self::$rewriteMap[$absoluteClassName];
}
return $absoluteClassName;
}
}
spl_autoload_register(['Yii', 'autoload'], true, true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册