Danura Aditya
Danura Aditya

Reputation: 73

Access Controller From Route In Slim

I have Some Routes On \src\routes.php

$app->get('/coba', 'App\controllers\HomeController:getfromcontroller');

And in myapp/app/controllers/HomeController.php like this

public function getfromcontroller((Request $request, Response $response){
     $response->withStatus(200)->write('Hello Motehr!');
}

and if i'am access http://localhost/myapp/public/coba thats errror

Type: RuntimeException Message: Callable App\controllers\HomeController does not exist File: C:\laragon\www\depoapi\vendor\slim\slim\Slim\CallableResolver.php Line: 90

Upvotes: 1

Views: 449

Answers (2)

iamafasha
iamafasha

Reputation: 794

They are three things that can happen here.

  1. Are all your URLs being redirected to the index.php in your public folder? in your case

    myapp/public.index.php

  2. Make sure you rename your controller folder to Controller and ensure your function is in the controller class.

  3. Try the solution in question 47724219 where you have to use the absolute namespace.

Upvotes: 0

Dastan
Dastan

Reputation: 206

Maybe you forgot to call the correct namespace:

$app->get('/coba', ['**YOURAPP**\App\controllers\HomeController', 'getfromcontroller']);

Upvotes: 0

Related Questions