这次更新了一下最新的版本,出现了一个问题来咨询一下,大致问题如下:
由于业务需要,我在分类里面扩展了一个字段,扩展字段的方法是按照YII的ClassMap来处理的,并配置了相关路径,程序也是能够run起来。
更新之后出现的问题是,程序仍然加载了我自己扩展的类,而我的类中并没有重写本次fecshop升级的增加一个是否在菜单显示的功能。
我是想了解一下,是否有什么更好的办法来重写class而不影响升级的内容?
比如:
这个是我重写的Category.php
<?php
namespace fecshop\models\mongodb;
use yii\mongodb\ActiveRecord;
class Category extends ActiveRecord
{
/**
* mongodb collection 的名字,相当于mysql的table name
*/
public static function collectionName()
{
return 'category';
}
/**
* mongodb是没有表结构的,因此不能像mysql那样取出来表结构的字段作为model的属性
* 因此,需要自己定义model的属性,下面的方法就是这个作用
*/
public function attributes()
{
return [
'_id',
'parent_id',
'name',
'status',
'url_key',
'level',
'thumbnail_image',
'image',
'filter_product_attr_selected',
'filter_product_attr_unselected',
'description',
'menu_custom',
'title',
'meta_description',
'meta_keywords',
'include_in_menu',
'is_feature',
'available_sort_by',
'default_sort_by',
'theme',
'active_from',
'active_to',
'created_at',
'updated_at',
'created_user_id',
'ori_id',
'sites'
//other
/*
category filter
category product
*/
];
}
}
本次升级的Category.php类:
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\models\mongodb;
use yii\mongodb\ActiveRecord;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Category extends ActiveRecord
{
const MENU_SHOW = 1;
const MENU_NOT_SHOW = 2;
const STATUS_ENABLE = 1;
const STATUS_DISABLE = 2;
/**
* mongodb collection 的名字,相当于mysql的table name
*/
public static function collectionName()
{
return 'category';
}
/**
* mongodb是没有表结构的,因此不能像mysql那样取出来表结构的字段作为model的属性
* 因此,需要自己定义model的属性,下面的方法就是这个作用
*/
public function attributes()
{
return [
'_id',
'parent_id',
'name',
'status',
'menu_show',//..这个为本次更新增加的字段
'url_key',
'level',
'thumbnail_image',
'image',
'filter_product_attr_selected',
'filter_product_attr_unselected',
'description',
'menu_custom',
'title',
'meta_description',
'meta_keywords',
'include_in_menu',
'is_feature',
'available_sort_by',
'default_sort_by',
'theme',
'active_from',
'active_to',
'created_at',
'updated_at',
'created_user_id',
//other
/*
category filter
category product
*/
];
}
}
由于ClassMap的配置,程序读取的是我自己写的Category.php,这样就相当于没有执行到更新内容,如何才能做到说重写Class并不影响升级功能的使用?还是说必须重新复制一下核心包的内容再次修改,这样文件重写多了升级会是一个很麻烦的事情?
本来我想利用继承关系来做,但是由于使用ClassMap,命名空间必须一致,无法使用继承来完成。
大家有没有好的思路呢?