2

I'm using Yii2-basic-app for now. I'm facing difficultly in calling class object in params.php.

I wanted to assign few params variable through database table's. And, I called using

params.php

$modelQueue =  new \app\modules\queue\models\Queues();

$params = [
  .
  .
  .
];

But, error coming

Fatal error: Class 'app\modules\queue\models\Queues' not found in /opt/lampp/htdocs/MyProject/config/params.php on line 13

Directory Structure

-assets
-commands
-components
-config
  -db.php
  -params.php
-controllers
-models
-modules
  -queue
    -controllers
    -models
      -Queues.php
    -views
    Queue.php
-runtime

I'm not getting how to call that class object. Because with help of this only I will set some data to params variable. Any help/hint/suggestions is appreciable.

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
  • Looks like the class you are calling there is not loaded yet. Is it necessary to set params at this stage? – Bizley Aug 17 '16 at 11:05
  • Yes. That is the problem. *~..class you are calling there is not loaded yet*.. Yes @Bizley. Need those table values here. – Nana Partykar Aug 17 '16 at 11:07
  • If you provide the purpose of `$modelQueue` in `params.php` maybe we can find the way around this problem. – Bizley Aug 17 '16 at 11:16
  • See, cron settings I wanted to use in this params.php from where I wanted to use it in code. @Bizley – Nana Partykar Aug 17 '16 at 11:18
  • You can always prepare method in `Queues()` that will return the value when it's needed so instead of calling `Yii::$app->params['some_parameter']` you can call `(new Queues())->preparedMethod()` or `Queues::preparedMethod()` in case of static one. – Bizley Aug 17 '16 at 11:40
  • I have same problem in yii2 advance app, some one suggest me Yii2's dependancy injection container, see this question: http://stackoverflow.com/questions/32689230/yii2-params-access-within-local-config-file-in-common-directory – Muhammad Shahzad Aug 17 '16 at 12:54
  • 1
    Useful Post @Shahzad *Bhai*. Happy Independence Day `:D` Shukriya – Nana Partykar Aug 17 '16 at 12:56

0 Answers0