Yii is awesome and fairly smooth sailing… my WebApp is mostly coded and have started creating my ‘nightlyprocess’ command so we can do nightly procedures. Have got my basic command running now and tests ok for basic querying of the database. The question is…
How do I access my existing functions I have created in my Model controllers??
I don’t want to duplicate my code, so should I be moving my existing functions to another location (extensions?). I want to access my emailInvoice & generatePDF functions etc that are currently sitting in my Controller files…
You could create application component classes like e.g. PdfCreator or Mailer that handle specific tasks in your application. It’s easy to write such a component (extends CApplicationComponent) and configure it as an application component (you can invent your own names for custom components as long as they don’t conflict with the predefined ones).
After that you can access these components from both, your controller action and your command line scripts.
// Typical usage example of components:
Yii::app()->mailer->sendWelcomeEmail($user);
...
$pdfFile=Yii::app()->pdf->createTimeReport($model)
awesome! many thanks for the direction here, will migrate my existing functions to that of a class similar to mailer and see how this works - again my thanks!
edit - too good, moved to my own component class and pointed my actions and console scripts to it and works perfectly - have to thank you again!