-
Notifications
You must be signed in to change notification settings - Fork 3
Controllers
Aouf Ali edited this page Dec 19, 2018
·
1 revision
Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller classes. Controllers can group related request handling logic into a single class. Controllers are stored in the /app/Controllers/ directory and should have the name nameController.php.
here is a basic controller class:
<?php
use Luna\Core\Controller;
use Luna\Services\Http\{Request, Response};
class UsersController extends Controller
{
public function __invoke()
{
echo "hello world!";
}
public function index($data,Request $request,Response $response)
{
echo "hello coders!";
}
}
You can define a route to this controller action like so:
Route::get('user/{id}', 'User@index');
# That's it! no other registration no other including! just this!notice: the url dynamic parts will be passed to your function in the array parameter data