Phalcon Command line applications

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.