Console
Consoles are scripts that start the application in background mode (without view and template). They are very used to cron sites
Defining a console route
Similar with a normal route, console route is defined in Bootstrap file:
namespace App; class Bootstrap extends \Core\Bootstrap { public function setConsoles() { return array( array('watch_price', '\Controllers\Hello@watchPrice'), array('update', '\Controllers\Hello@update'), ); } }
And in controller:
public function watchPriceAction() { // Business logic echo "Done!\r\n"; } public function updateAction() { // Business logic echo "Updated!\r\n"; }
Create the script
All scripts would need to stay in /scripts folder.
An example of script:
// Autoload files using Composer autoload require_once __DIR__ . '/../vendor/autoload.php'; $app = new \Core\Crater($argv); $app->run();
Execute your script
Write in console:
$ cd /var/www/crater/scripts $ php console.php update Updated!↑