PHP code example of benmajor / slim3-controller

1. Go to this page and download the library: Download benmajor/slim3-controller library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

benmajor / slim3-controller example snippets




namespace MyApp\App\Controller;

use BenMajor\Slim3Controller\Controller;

class ContactController extends Controller
{
  public function index()
  {
    return $this->render('contact-main.twig', [ /* view data here */ ]);
  }
  
  public function send()
  {
    // Handle the sending of the contact form.
  }
}



use MyApp\App\Controller;

// Define the controllers:
$controllers = [
  'contact' => new ContactController($app)
];

$app->group('/contact', function() use ($app, $controllers) {
  $app->get('/', $controllers['contact']('index'));
  $app->post('/', $controllers['contact']('send'));
});