Fatal Error: Class 'AnyModel' not found in: /var/www/app/controllers/AnyController.php


Nginx site config:

server {
  listen   80;

  index index.php index.html index.htm;
  set $root_path '/var/www/public';
  root $root_path;

  try_files $uri $uri/ @rewrite;

  location ~ ^/(status|ping)$ {
     access_log off;
     include fastcgi_params;
     fastcgi_pass unix:/var/run/php5-fpm.sock;

  location @rewrite {
      rewrite ^/(.*)$ /index.php?_url=/$1;

  location ~ \.php {
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index /index.php;

      include fastcgi_params;

      fastcgi_split_path_info       ^(.+\.php)(/.+)$;
      fastcgi_param PATH_INFO       $fastcgi_path_info;
      fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

  location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
      root $root_path;

  location ~ /\.ht {
      deny all;

PHP-FPM config - default


2015/04/23 21:16:22 [error] 23921#0: *3 FastCGI sent in stderr: "PHP message: PHP Fatal error: Class 'y' not found in /var/www/app/controllers/yController.php on line 21" while reading response header from upstream, client: x.x.x.x, server: 176.31.x.x, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "176.31.175.x"


It may be helpful if we can see the code of that yController.php. :)

edited Apr '15

For example: $model = AnyModel::Find("id='3'");

Phalcon just can't include models. IDK why

P.s Phalcon 2.0


if believe your code is like this: y::find("id=3"); ? if that's the case that means you should have a model y.

If you want to call a function of the same controller class, why not use self:: or $this->?

On my local server all works good (MAMP)

edited Apr '15

My knowledge is quite limited. But I do have similar problem before. The same piece of code may not work if the OS are different, there is a "safe build" of Phalcon and that gave me a temporary fix (I personally do not know much about the "safe build" and the others). Please look at this thread http://forum.phalconphp.com/discussion/1540/problems-with-aws-beanstalk-and-phalcon.

good luck man :) so far I do think Phalcon is super awesome!

lol. I have copied source of AnyModel into AnyController and all works... All works too when I have added include to model file.

(sry for bad english)


wait, that's strange. It should be somewhat "automatic" if the registerDirs of Loader works.

Could you post your autoloader configuration ?

On my local server all works good.

use Phalcon\Loader;
use Phalcon\Tag;
use Phalcon\Mvc\Url;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\DI\FactoryDefault;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;

 try {
  // Register an autoloader
  $loader = new Loader();

  // Create a DI
  $di = new FactoryDefault();

  // Set the database service
  $di['db'] = function() {
      return new DbAdapter(array(
          "host"     => "localhost",
          "username" => "root",
          "password" => "pass",
          "dbname"   => "db"

  // Setting up the view component
  $di['view'] = function() {
      $view = new View();

          ".volt" => 'Phalcon\Mvc\View\Engine\Volt'

      return $view;

  // Setup a base URI so that all generated URIs include the "tutorial" folder
  $di['url'] = function() {
      $url = new Url();
      return $url;

  // Setup the tag helpers
  $di['tag'] = function() {
      return new Tag();

  $di->setShared('session', function() {
    $session = new Phalcon\Session\Adapter\Files();

    return $session;

  // Handle the request
  $application = new Application($di);

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

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


@TwinkerMan I assume you tested the model class with "class_exists"?