dongningce9075 2015-10-19 12: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 12: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 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题