商城后台新增虚拟卡券模块问题

问题咨询 · Andrew · 于 5年前 发布 · 2029 次阅读

在商城后台二开一个卡券配置模块的时候,请求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 文档来开发的,核对了好几遍,没有找到问题。 麻烦大牛有空的时候帮我分析下是什么文件配置错了还是少配置了,谢谢。

共收到 13 条回复
Andrew#15年前 0 个赞

controller 模块和方法都是可以进去的,只有在调用Yii::$service->coupon的时候会报上边的错误

Andrew#25年前 0 个赞

common/config/local_services/Coupon.php代码如下: return [

'coupon' => [
    'class' => 'common\local\local_services\Coupon',
    'storage' => 'CouponMysqldb',
],

];

3楼 已删除.
Andrew#45年前 0 个赞

新增代码目录如下:

Fecmall#55年前 0 个赞

1.发了帖子,仔细看一下信息是否完善

2.你既然这个文件报错 common\local\local_services\Coupon ,那么你这个文件的代码呢?这个文件里面的代码不写,谁知道是哪里导致的问题?

show your code !!!

Fecmall#65年前 0 个赞

添加 services的报错,文档是:http://www.fecshop.com/doc/fecshop-guide/develop/cn-1.0/guide-fecshop-service-use.html

你贴的那个文档地址是添加modules, 本帖子报错的问题是添加services的报错,而不是添加modules!!

Andrew#75年前 0 个赞

@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();
    }
}

Fecmall#85年前 0 个赞

@Andrew [#7楼](#comment7) 仔细看回复的内容,无脑看回复吗?

Andrew#95年前 0 个赞

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);
    }

}
Andrew#105年前 0 个赞

@Fecshop #8楼 我看了您发的这篇文章 http://www.fecshop.com/doc/fecshop-guide/develop/cn-1.0/guide-fecshop-service-use.html ,代码确实是按照这个方式配置的,您可以结合2楼和9楼的代码看下

Andrew#115年前 0 个赞

感觉是storage这个东西没有注进来

Andrew#125年前 0 个赞

@Fecshop #8楼 问题解决了,appadmin里的fecshop_local_services模块没有加service这个代码,导致controller找不到这个service,开始以为是在common里加上就不用再appadmin里加了:persevere:

Fecmall#135年前 0 个赞

@Andrew #12楼

OK,services是各个入口公用的部分配置

1.如果这个services你想appadmin独有使用,那么你可以在@appadmin/config/fecshop_local_services/coupon.php中添加配置

2.如果这个services你想所有的入口都可以使用,那么你可以在@common/config/fecshop_local_services/coupon.php中添加配置

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics