你上面使用搞错了,具体的使用,我这里有一篇文章,你没有仔细看:
通过配置的方式重写某个Yii2 文件 或第三方扩展文件,Yii2 classMap
你的使用犯了好几个错误:
1.配置出错
<?php
return [
//'fecshop\app\appfront\helper\test\My' => '@appfront/helper/My.php',
"fecshop\models\mongodb\Category"=>"appadmin\local\local_models\mongodb\Category.php",
];
你看你上面的注释里面的配置,你在看你的配置,你都没有按照注释来,注释已经写了一个例子。应该改为:
<?php
return [
//'fecshop\app\appfront\helper\test\My' => '@appfront/helper/My.php',
"fecshop\models\mongodb\Category"=>"@appadmin/local/local_models/mongodb/Category.php",
];
第二个错误,你的重写后的Category.php,也就是你的 appadmin\local\local_models\mongodb\Category.php
文件的namespace,必须使用 你要重写的文件的namespace,也就是fecshop\models\mongodb
,你重写后的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',//..此处为增加字段
//other
/*
category filter
category product
*/
];
}
}
这两个错误搞定后,就可以了。