Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Cli

Hi,

I have a problem with Cli which is working on localhost(apache2):

<?php

use Phalcon\DI\FactoryDefault\Cli as CliDI,
    Phalcon\Cli\Console as ConsoleApp,
    Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;

$di = new CliDI();
define('__URL__', 'milan.local');
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__)));

$loader = new \Phalcon\Loader();

$loader->registerDirs(array(
        APPLICATION_PATH . '/tasks'
))->register();

$loader->registerNamespaces(array(
    'Models\Settings' => APPLICATION_PATH . '/models/settings/',
    'Models\User' => APPLICATION_PATH . '/models/user/',
    'Library' => APPLICATION_PATH . '/library/'
))->register();

if (is_readable(APPLICATION_PATH . '/config/config.php')) {
    $config = include APPLICATION_PATH . '/config/config.php';
    $di->set('config', $config);
}

$console = new ConsoleApp();
$console->setDI($di);

$arguments = array();
foreach ($argv as $k => $arg) {
    if ($k == 1) {
        $arguments['task'] = $arg;
    } elseif ($k == 2) {
        $arguments['action'] = $arg;
    } elseif ($k >= 3) {
        $arguments['params'][] = $arg;
    }
}

$di->set('db', function () use ($config) {
    return new DbAdapter(array(
        'host' => $config->database->host,
        'username' => $config->database->username,
        'password' => $config->database->password,
        'dbname' => $config->database->dbname,
        'charset' => $config->database->charset,
    ));
});

define('CURRENT_TASK',   (isset($argv[1]) ? $argv[1] : null));
define('CURRENT_ACTION', (isset($argv[2]) ? $argv[2] : null));

try {
    $console->handle($arguments);
} catch (\Phalcon\Exception $e) {
    echo $e->getMessage();
    exit(255);
}

but at the server i have an error:

PHP Fatal error: Class 'Phalcon\DI\FactoryDefault\Cli' not found in /var/www/clients/client1/web2/web/app/cli.php on line 7

What am I doing wrong?

Please, help me.

Regards, nansss

edited Aug '16

First of all, CLI apps have nothing to do with the webserver (apache2) :]

As for you problem, you most probably haven't enabled the phalcon extension. If you installed php from the package manager, you can do this:

echo 'extension=phalcon.so' > /etc/php5/mods-available/phalcon.ini
php5enmod phalcon

Or you can manually set it up (only for the cli SAPI):

echo 'extension=phalcon.so' >> /etc/php5/cli/php.ini

OR

echo 'extension=phalcon.so' >> /etc/php5/php-cli.ini

The point is, add extension=phalcon.so to your ini file



1.1k

I have the phalcon extension on nginx /etc/php5/fpm/conf.d/30-phalcon.ini and mvc application works normally



107.5k
Accepted
answer

As already wrote, nginx and fpm don't havy ANYTHING to do with CLI app. Are you have the same file under /etc/php5/cli/conf.d ?



1.1k

Thanks. There was my mistake. I had /etc/php5/cli/conf.d/30-phalcon.so instead /etc/php5/cli/conf.d/30-phalcon.ini

Now it is everything ok so topis to close.