dongningce9075 2015-10-19 04:24
浏览 48
已采纳

为foreach()yii-app-basic提供的参数无效

I've one module -> users.

->modules
    ->users
        ->controllers
        ->models
        ->views
        ->Users.php

I created one 'config.php' inside 'config' folder of 'users' modules.

->modules
    ->users
        ->config
            ->config.php
        ->controllers
            -> List of Controllers
        ->models
            -> List of models
        ->views
            -> List of Views
        ->Users.php

And, i gave directory path of config.php in init() method of Users.php, as

modules/users/Users.php

<?php

namespace app\modules\users;

class Users extends \yii\base\Module
{
    public $controllerNamespace = 'app\modules\users\controllers';
    public $commonModel = 'app\modules\users\models\Users';

    public function init()
    {
        parent::init();
        \Yii::configure($this,require(__DIR__.'/config/config.php'));
    }
}

But, it is giving error like

PHP Warning – yii\base\ErrorException
"Invalid argument supplied for foreach()".

Screenshot

enter image description here enter image description here enter image description here enter image description here

I am taking reference from Yii2.0 Guide to include a path inside init() method.

Please help me to rectify this issue.

Thanks.

展开全部

  • 写回答

3条回答 默认 最新

  • dongshao1981 2015-10-19 04:51
    关注

    From what I can see, you're passing in the PHP code to your config file, instead of passing in a configuration array

    Instead of this...

    \Yii::configure($this, require(__DIR__.'/config/config.php'));
    

    Try doing this...

    $config = require(__DIR__.'/config/config.php');
    \Yii::configure($this, $config);
    

    In your config.php file you should be returning an array, if you're using the basic-app config file and adding to that then it should be set up like this already

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部