-1

What is the best way to reuse code between controller and command? I have some use where the very same logic should be executed inside controller and in command as well. What is the best approach to share code? To create a component and the call this component methods from controller and command?

gandra404
  • 5,727
  • 10
  • 52
  • 76

1 Answers1

1

Create a class (model, service, etc), and use that in the different areas. Within the config/main.php or config/console.php there is an import section:

'import' => array( 'application.models.*', 'application.components.*',

You can add your class anywhere really, as long as its location is referenced within the import section in the config, as that is how Yii1 autoloads files.

Adoni
  • 146
  • 4