Error in call controller, Callable ...Controller does not exist


#1

I’m new in userfrosting, i have a “prueba” sprinkle, in routes, i have 2:

    $app->get('/prueba/uno', function ($request, $response, $args) {
            return $response->write("Ruta sin parametro uno");   
    });

    $app->get('/prueba/cinco', 'UserFrosting\Sprinkle\Prueba\Controller\PruebaController:getMsg');

In sprinkles\prueba\src\controller\PruebaController.php contains:

namespace UserFrosting\Sprinkle\Prueba\Controller;

use UserFrosting\Sprinkle\Core\Controller\SimpleController;

class PruebaController extends SimpleController
{
    public function getMsg($request, $response, $args)
    {
            return $response->write("Respuesta desde controlador");
    }

}

I need to change some files?? in another thread mention “./composer.json” and “./vendor/composer/autoload_psr4.php” but in tutorial don’t mention it…

regards


#2

Excuse me… create composer.json with

 {
        "autoload": {
             "psr-4": {
                 "UserFrosting\\Sprinkle\\Prueba\\": "src/"
             }
         }
     }

then composer update in sprinkle directory, exists another form without “composer update”?? how?

regards


#3

PSR-4 is case-sensitive. Composer maps the subdirectories under the src/ directories to namespaces of the same name (including case). Since the namespace you are trying to use is UserFrosting\Sprinkle\Prueba\Controller, you need to capitalize your controller directory like so:

sprinkles\prueba\src\Controller\PruebaController.php

Notice that the parent directories should remain lowercase. Only directories under src/ should be capitalized.