0
I am creating an MVC application where there is dependency injection to instantiate the classes with connection to the database, the problem is when I climbed the application to a remote server, when I try to access I get the following error "Uncaught Error: Class ' App Models Records' not found in ..."
Error itself is in the Container.php file
namespace SON\DI;
class Container
{
public static function getClass($name)
{
$str_class = "\\App\\Models\\".ucfirst($name);
$class = new $str_class(\App\Init::getDb());
return $class;
}
}
It is called in the Submissaocontroller class
$registros = \SON\DI\Container::getClass("Registros");
It also follows the Register.php class analogous to all other Model classes that would use Injection
namespace App\Models;
class Registros {
protected $db;
public function __construct (\PDO $db)
{
$this->db = $db;
}
The curious thing is that the code works locally but is not working on the host, I’ve reviewed forums but got no answer.
Didn’t miss uploading this file to the server? It is inserted on the executed page?
– Costamilam
Yes, it is on the server, I did not understand the inserted on the page, you meant what? give a include on it?
– Lucas Gonçalves
Yes
include
orrequire
or using autoload– Costamilam
the application has that autoload of Composer that is created when we install by cmd, but I don’t understand how exactly it works, or if I have to apply something to the server about it
– Lucas Gonçalves
You must configure the property
psr-4
ofcomposer.json
(at a glance in that question) should be the problem. Also be sure to run thecomposer dump-autoload
to update the autoload– Costamilam
Okay, I’ll do it, but I don’t have access to ssh from the remote server so I can cump-autoload here on site and stream the files to the server? or I really need to find a way to get ssh?
– Lucas Gonçalves
No need, just do it on location and then pass the files to the remote
– Costamilam
I executed the autoload steps by inserting the following way, { "name": "son/mvc", "require": { "php": ">=5.3" }, "autoload": { "psr-4": { "SON ": "vendor/SON/", "App ": "App/" } }, "config": { "bin-dir": "bin" } }
– Lucas Gonçalves
even with the commands and the upload on the server I continue with the class problem
– Lucas Gonçalves
Actually the problem was connected to . Htacess server, it made Autoload work in the wrong way, after changing it I was able to make it work.
– Lucas Gonçalves
Since you solved the problem, post an answer with the file before and after the correction explaining. Will help future users who have the same problem
– Costamilam