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

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

Server: NGINX + PHP-FPM

Nginx site config:

server {
  listen   80;
  server_name 176.31.175.91;

  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

Error:

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"



25.7k

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



25.7k

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)



25.7k
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 https://forum.phalcon.io/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)



25.7k

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.

<?php
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();
  $loader->registerDirs(
      array(
          '../app/controllers/',
          '../app/models/'
      )
  )->register();

  // 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();
      $view->setViewsDir('../app/views/');

      $view->registerEngines(array(
          ".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();
      $url->setBaseUri('/');
      return $url;
  };

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

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

    return $session;
  });

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

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

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


25.7k

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