Arfeen
Arfeen

Reputation: 2623

Yii: Calling Yii::app()->controller from Yii Console application

I'm working in a Yii project which also have a console application.

Form the console app, I'm not calling any controller and working only on components which work fine but at someplaces, I need to call the variables / functions from Controller.php in components directory. That can be called for e.g.

Yii::app()->controller->aGlobalVariable;

But in console app, I'm not able to do that and it says:

Trying to get property of non-object ...

How do I make console app use it ?

Thanks

Upvotes: 2

Views: 4169

Answers (1)

Sergey
Sergey

Reputation: 5207

In console you use CConsoleApplication which do not have controllers, you may use models of class inherited from CConsoleCommand

yiic {your command} {your params for command}

Ask Google: https://www.google.ru/search?q=yii+CConsoleCommand

I need to call the variables / functions from Controller.php

You recode your vars and functions into stand alone class in \protected\components\, which you may call from controllers and consolecommand.

Upvotes: 1

Related Questions