在商城后台二开一个卡券配置模块的时候,请求controller报错,问题如下: Invalid Configuration – yii\base\InvalidConfigException Missing required parameter "id" when instantiating "appadmin\local\local_modules\Coupon\Module". 我是按照http://www.fecshop.com/doc/fecshop-guide/develop/cn-1.0/guide-fecshop-appadmin-developer.html 文档来开发的,核对了好几遍,没有找到问题。 麻烦大牛有空的时候帮我分析下是什么文件配置错了还是少配置了,谢谢。
common/config/local_services/Coupon.php代码如下: return [
'coupon' => [
'class' => 'common\local\local_services\Coupon',
'storage' => 'CouponMysqldb',
],
];
1.发了帖子,仔细看一下信息是否完善
2.你既然这个文件报错
common\local\local_services\Coupon
,那么你这个文件的代码呢?这个文件里面的代码不写,谁知道是哪里导致的问题?
show your code !!!
添加 services的报错,文档是:http://www.fecshop.com/doc/fecshop-guide/develop/cn-1.0/guide-fecshop-service-use.html
你贴的那个文档地址是添加modules, 本帖子报错的问题是添加services的报错,而不是添加modules!!
@Fecshop #5楼
appadmin\local\local_modules\Coupon\Module 代码如下:
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace appadmin\local\local_modules\Coupon;
use fec\AdminModule;
class Module extends AdminModule
{
public function init()
{
// 以下代码必须指定
$this->controllerNamespace = __NAMESPACE__ . '\\controller';
$this->_currentDir = __DIR__;
$this->_currentNameSpace = __NAMESPACE__;
// 指定默认的man文件
$this->layout = '/main_ajax.php';
parent::init();
}
}
@Andrew [#7楼](#comment7) 仔细看回复的内容,无脑看回复吗?
common\local\local_services\Coupon 代码如下:
<?php
namespace common\local\local_services;
use fecshop\services\Service;
use Yii;
class Coupon extends Service
{
/**
* $storagePrex , $storage , $storagePath 为找到当前的storage而设置的配置参数
* 可以在配置中更改,更改后,就会通过容器注入的方式修改相应的配置值
*/
public $storage; // 当前的storage,在config中配置,在初始化的时候会被注入修改
/**
* 设置storage的path路径,
* 如果不设置,则系统使用默认路径
* 如果设置了路径,则使用自定义的路径
*/
public $storagePath;
protected $_coupon;
public function init()
{
parent::init();
$currentService = $this->getStorageService($this);
$this->_coupon = new $currentService();
}
/**
* get artile's primary key.
*/
protected function actionGetPrimaryKey()
{
return $this->_coupon->getPrimaryKey();
}
/**
* get artile model by primary key.
*/
protected function actionGetByPrimaryKey($primaryKey)
{
return $this->_coupon->getByPrimaryKey($primaryKey);
}
/**
* 得到category model的全名.
*/
protected function actionGetModelName()
{
return get_class($this->_coupon);
}
/**
* @property $filter|array
* get artile collection by $filter
* example filter:
* [
* 'numPerPage' => 20,
* 'pageNum' => 1,
* 'orderBy' => ['_id' => SORT_DESC, 'sku' => SORT_ASC ],
'where' => [
['>','price',1],
['<=','price',10]
* ['sku' => 'uk10001'],
* ],
* 'asArray' => true,
* ]
*/
protected function actionColl($filter = '')
{
return $this->_coupon->coll($filter);
}
/**
* @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.
*/
protected function actionSave($one, $originUrlKey)
{
return $this->_coupon->save($one, $originUrlKey);
}
protected function actionRemove($ids)
{
return $this->_coupon->remove($ids);
}
}
@Fecshop #8楼 我看了您发的这篇文章 http://www.fecshop.com/doc/fecshop-guide/develop/cn-1.0/guide-fecshop-service-use.html ,代码确实是按照这个方式配置的,您可以结合2楼和9楼的代码看下