Problem for instantiating class

Asked

Viewed 106 times

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?

  • Yes, it is on the server, I did not understand the inserted on the page, you meant what? give a include on it?

  • Yes include or require or using autoload

  • 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

  • You must configure the property psr-4 of composer.json (at a glance in that question) should be the problem. Also be sure to run the composer dump-autoload to update the autoload

  • 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?

  • No need, just do it on location and then pass the files to the remote

  • 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" } }

  • even with the commands and the upload on the server I continue with the class problem

  • 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.

  • 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

Show 6 more comments

1 answer

0


the code contained in . htacess is

RewriteEngine On

Rewritecond %{REQUEST_URI} ! public [OR] Rewritecond %{REQUEST_FILENAME} ! -s [OR] Rewritecond %{REQUEST_FILENAME} ! -l [OR] Rewritecond %{REQUEST_FILENAME} ! -d Rewritecond %{REQUEST_URI} !.(?:css|js|jpe?g|gif|png) $ [NC] Rewriterule .*$ public/index.php [NC,L]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.