By default, all of the controllers for your application are stored in the app/controllers/ directory.
Here is a basic controller example. In this example we are displaying the Hello World!
// app/Controllers/HomeController.php
namespace App\Controllers;
class HomeController{
public function index(){
return "Hello world";
}
}
We can also display the Hello World using echo or print_r without return
// app/Controllers/HomeController.php
namespace App\Controllers;
class HomeController{
public function index(){
echo "Hello world";
//or
print_r("Hello world");
}
}
The controller usage is identical to that specified when registering the route.
// routes/api.php
use Ghosty\Framework\Support\Facades\Route;
Route::get('/home')
->controller(\App\Controllers\HomeController::class)
->action('index');