Today, I'm going to add a scheduled task under the Phalcon project to send mail.
See the official website example, configuration and operation are a little messy, there is a bug, see Remarks, my side mainly explain how to command line configuration independent out, if the beginning of the classmate, recommended first Run official website example, success, then practice the second official website example, an error occurred, see my notes, And then look at me. This is how the configuration is handled independently.
learn from the idea: the main reference in the YII framework, similar function commands configuration console.php.
Step one: Create three files under the Tasks folder under the app:
cl_config.php //Copy the contents of the app/config/config.php directly in
cl_loader.php //The same app/config/loader.php content copy into, pay attention to some choice, such as Modelsdir, with the database, but controllersdir there is no use, can be commented out
cl_services.php //also copy in, but $di do not need to regenerate, directly with the good, the useless are commented out, generally only reserved $di->set (' db ' .... That paragraph
Step Two: Modify the cli.php file under the app
if (Is_readable (Application_path. '/tasks/cl_config.php ') {//import cl_config.php
$config = include Application_path. '/tasks/cl_config.php ';
$di->set (' config ', $config);
}
Include Application_path. "/tasks/cl_loader.php"; Now introduce Autoloader,
Include Application_path. "/tasks/cl_services.php"; Introduction of Cl_services
Ok,,,,
Note:
Part of the configuration in the cli.php
$arguments = Array ();
foreach ($argv as $k = = $arg) {
if ($k = = 1) {
$arguments [' task '] = $arg;
} elseif ($k = = 2) {
$arguments [' action '] = $arg;
} elseif ($k >= 3) {
$arguments [] = $arg; Need to be changed to $arguments [' params '] [] = $arg; Otherwise, on the command line with the parameters run, will be error, as follows
}
}
run : $ php app/cli.php main test ff SS ww mm
Error content:
PHP catchable fatal Error:argument 1 passed to Maintask::testaction () must is of the type array, string given in/users/ liangzhongyuan/sites/library/app/tasks/maintask.php on line 24
Catchable fatal Error:argument 1 passed to Maintask::testaction () must is of the type array, string given In/users/liang zhongyuan/sites/library/app/tasks/maintask.php on line 24
Related connections:
Http://www.myleftstudio.com/reference/cli.html//website explanation