S
S
Sergey Beloventsev2017-05-22 20:53:13
Yii
Sergey Beloventsev, 2017-05-22 20:53:13

How to use $this->module in static methods?

actually in my extension I'm trying to implement a connection either to the database through migration, or if the user has his own table for settings, then the user's table is actually the code

public static function tableName()
    {
        $module=self::module;
        if(empty($module->modelDb)){
            return '{{%menu_table}}';
        }else{
            return $module->dbName->name;
        }
    }

actually here is the project on the gith but an error falls out
Undefined class constant 'module'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-05-23
@Sergalas

First of all, $this->module is not a static property, so it cannot be used in static methods. Secondly, as far as I understand the code that you brought to be in the model, and the module property in the controller.
In your case, the easiest way to get to the module properties is like this:
MyModule::getInstanse()->propertyName

M
Mykola, 2017-05-23
@iSensetivity

Yii::$app->getDb();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question