我的操作步骤如下:
1、composer create-project yiisoft/yii2-app-advanced myapp
2、cd fecshop
3、./init
4、./yii migrate
安装yii2成功
5、我在 frontend\web\index.php 文件加入如下代码:
$config = yii\helpers\ArrayHelper::merge(
...
require __DIR__ . '/../../common/config/services.php'
...
)
new common\services\Application($config['services']);
unset($config['services']);
6、复制 fancyecommerce\fecshop\services\Application.php 文件和 fancyecommerce\fecshop\services\Service.php 文件到 common\services\ 下,并把 namespace 的命名空间改到common下
7、复制 fancyecommerce\fecshop\config\fecshop.php 文件到 common\ 下,并改名为 services.php,并新建common\config\components 和 common\config\services 两个目录
8、复制 fancyecommerce\fecshop\config\services\Cart.php 文件到 common\config\services\ 下
9、然后在 frontend\web\index.php 文件中打印 print_r($config['services']); 结果如下
Array ( [cart] => Array ( [class] => fecshop\services\Cart [childService] => Array ( [quote] => Array ( [class] => fecshop\services\cart\Quote ) [quoteItem] => Array ( [class] => fecshop\services\cart\QuoteItem ) [info] => Array ( [class] => fecshop\services\cart\Info [maxCountAddToCart] => 100 [addToCartCheckSkuQty] => ) [coupon] => Array ( [class] => fecshop\services\cart\Coupon ) ) ) )
10、但 Yii::$service 功能还是不能使用,报如下错误,大佬指点下,还差什么
Fatal error: Uncaught Error: Access to undeclared static property: Yii::$service in /wwwroot/myapp/common/services/Application.php:68 Stack trace: #0 /wwwroot/myapp/frontend/web/index.php(25): common\services\Application->__construct(Array) #1 {main} thrown in /wwwroot/myapp/common/services/Application.php on line 68