Controllers - Icybrew/Stackoverflow-documentation GitHub Wiki
Controllers are responsible for your logic about the page, it talks with model (if necessary) and renders page using inherited view method.
/* app/controllers/IndexController.php */
<?php
namespace App\Controllers;
class indexController extends Controller
{
public function index() {
$customData = [
'title' => 'Hello World'
];
// First parameter is your view which resides inside 'resources/views/<name>.php', second is optional variable
$this->view('index', $customData);
}
}
/* resources/views/index.php */
<h1><?php echo $data['title'] ?></h1>
- Every controller must inherit base Controller
- You can also pass data for your view to use!