1
I am creating a test framework. I use Composer to create the structure of my project. The file Composer.json looks like this:
{
"autoload": {
"psr-4": {
"App\\": "src/app/mvc/"
}
}
}
I divided my project with the following structure:
C: xampp htdocs webapp src app mvc\
In mvc I have the following subfolders: controller; model; view
Since I’m having trouble with namespace.
For example for the /model/model.php the code was left:
<?php
namespace App;
class Model
{
public function getText($str = 'Olá mundo!')
{
return $str;
}
}
For the controller/controller.php the code was left:
<?php
namespace App\controller;
class Controller
{
public function index()
{
$model = new model\Model;
$view = new view\View;
$view->render($model->getText());
}
}
php is returning an error in the.php controller Fatal error: Class 'App controller model Model' not found in C: xampp htdocs webapp src app mvc controller Controller.php on line 7
Would anyone know what is wrong with configuring psr4.
Try this
new \App\model\Model;
– Guilherme Nascimento
@Guilhermebirth with this modification in the controller.php file when trying to instantiate the model gives the following error: Fatal error: Class 'App controller app model Model' not found in C: xampp htdocs webapp src app mvc controller Controller.php on line 7
– Bruno Nascimento
Is Model in the same folder as Controller? It doesn’t make much sense this error, you put the bar in front that I suggested? Thus
new \App\model\Model;
and nay thusnew App\model\Model;
– Guilherme Nascimento