We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Can't extend a class in a CLI application

Hi, title is clear. I can't extend a class in my CLI application. All the following classes are in the lib folder :

class FraudTask extends \Phalcon\CLI\Task {

    public function mainAction() {

        $liveFraud = new LiveFraud();
        $liveFraud->execute();

        //$liveMobileFraud = new LiveMobileFraud();
        //$liveMobileFraud->execute();
    }
}

class LiveFraud extends Fraud {
}

abstract class Fraud  {
}

In my config file :

$loader->registerDirs(

array(

    APPLICATION_PATH . '/tasks',
    APPLICATION_PATH . '/models',
    APPLICATION_PATH . '/lib',
));

$loader->register();

When I execute : php cli.php fraud

Fatal error: Class 'Fraud' not found in /Library/WebServer/Documents/tuangocli/app/lib/LiveFraud.php on line 30

I don't understand why the class is not found.

edited May '14

It seems that the class is not loaded properly. Please try to put the class into a namespace and register the namespace.

Like this:

namespace Acme;

abstract class Fraud  {

}
$loader->registerNamespace(array(
'Acme' => '/path/to/lib'
));

Registering namespaces is more efficient then registering directories. You need to do this for the other classes as well.



31.3k

Hi, it's funy because I got another post for the same problem, but with namespace. In other word, I already try with namespace and I got the same result.

https://forum.phalcon.io/discussion/2337/namespace-model-in-cli

Thank you !