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

Model class named issue

Hi everyone,

Phalcon cannot support Model class named including "_" , right? As we create the Model class named as User_log,but Phalcon unable support,and show below error : Fatal error: Class 'User_log' not found

Then we also create the Model class named as Userlog,and Phalcon can support on this, pls kindly advice how to config Phalcon to support "_" named in Model name. thanks.

And you sure that file name is User_log too ? You should follow PSR anyway.

Hi Guy,

yes i am sure the file name is User_log.class,below is my User_log.class content:

use Phalcon\Mvc\Model; class User_log extends Model{ public function initialize(){ $this->getSource("forum_user_log"); } }

And you sure that file name is User_log too ? You should follow PSR anyway.

edited Jul '16

You mean User_log.php ? And how you are loading it with loader ? Remember that phalcon follows PSR-0:

https://www.php-fig.org/psr/psr-0/#underscores-in-namespaces-and-class-names

So if you have User_log class it should be stored under root folder/User/log.php

Hi guy,

yes the file name is User_log.php in Model directory ,and including below User_log class.

below code is my index.php with loader in root/public/

<?php use Phalcon\Loader; use Phalcon\Mvc\View; use Phalcon\Mvc\Url as UrlProvider; use Phalcon\Mvc\Application; use Phalcon\DI\FactoryDefault; use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter; use Phalcon\Session\Adapter\Files as Session; use Phalcon\Mvc\Router;

try { $loader = new Loader(); $loader->registerDirs(array( '../apps/controllers/', '../apps/models/' ))->register();

// Create a DI
$di = new FactoryDefault();
$di->set('db',function(){
    return new DbAdapter(array(
        'host' =>'localhost',
        'username' =>'root',
        'password' =>'root',
        'dbname'   =>'forum'
        ));
    });

// Setup the view component
$di->set('view', function () {
    $view = new View();
    $view->setViewsDir('../apps/views/');
    return $view;
});

 $di->set('url', function () {
     $url = new UrlProvider();
     $url->setBaseUri('/');
     return $url;
 });

 $di->setShared("session", function(){
      $session= new Session();
      $session->start();
      return $session;
  });

 $di->set("modelsCache", function (){
     $frontCache = new Phalcon\Cache\Frontend\Data(
         array(
             "lifetime"  => 86400
         ));
     $cache = new Phalcon\Cache\Backend\Memcache($frontCache,array(
         "host"  => "localhost",
         "port"  => "11211"
     ));
     return $cache;
 });

 $application = new Application($di);

 echo $application->handle()->getContent();

} catch (\Exception $e) { echo "PhalconException: ", $e->getMessage(); }

You mean User_log.php ? And how you are loading it with loader ? Remember that phalcon follows PSR-0:

https://www.php-fig.org/psr/psr-0/#underscores-in-namespaces-and-class-names

So if you have User_log class it should be stored under root folder/User/log.php

Then as i wrote. Phalcon loader follow PSR-0. If you are accessing User_log class name then it must be in /apps/models/User/log.php folder according to PSR-0. Why you just don't use CamelCase ?