Hi,
I have a MVC application inside which I want to include a CLI project and call a task from a controller. Is this possible ? By the way, each element works fine except when I combine both.
Folder structure :
MyApp
app
config
controllers
MyController.php
models
tasks
MyTask.php
views
cli.php
Controller :
use Phalcon\Mvc\Model\Criteria;
use Phalcon\Paginator\Adapter\Model as Paginator;
class MyController extends ControllerBase {
public function cliAction() {
if (filter_input(INPUT_GET, 'ORDERID', FILTER_SANITIZE_ENCODED)) {
$orderID = filter_input(INPUT_GET, 'ORDERID', FILTER_SANITIZE_ENCODED);
$subscriberID = filter_input(INPUT_GET, 'SUBSCRIBERID', FILTER_SANITIZE_ENCODED);
$email = filter_input(INPUT_GET, 'CUSTOMEREMAIL', FILTER_SANITIZE_EMAIL);
if (filter_input(INPUT_GET, 'IP', FILTER_SANITIZE_ENCODED)) {
$IP = filter_input(INPUT_GET, 'IP', FILTER_SANITIZE_ENCODED);
} else {
$IP = filter_input(INPUT_SERVER, 'REMOTE_ADDR');
}
exec("php app/cli.php task main $orderID $subscriberID $email $IP");
$this->view->disable();
}
}
}
Task :
class mytaskTask extends \Phalcon\CLI\Task {
public function mainAction(array $param) {
$orderID = $param[0];
$subscriberID = $param[1];
$email = $param[2];
$IP = $param[3];
$timeZone = new DateTimeZone('America/Montreal');
$date = new DateTime();
$date->setTimezone($timeZone);
$transactionDate = $date->format('Y-m-d h:i:s');
$transactionLog = new TransactionLog();
$transactionLog->IP = $IP;
$transactionLog->Email = $email;
$transactionLog->OrderID = $orderID;
$transactionLog->SubscriberID = $subscriberID;
$transactionLog->TransactionDate = $transactionDate;
$transactionLog->create();
}
}
Thank you!