PHP code example of redreams / slim-annotation-based

1. Go to this page and download the library: Download redreams/slim-annotation-based 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/ */

    

redreams / slim-annotation-based example snippets

 php

use Redreams\Slim\App;
//front controller (index.php)
$config = [];//defaul slim config
$config['settings']['routerCacheDir'] = './dirForDoctrineAnnotationReader';//optional
$app = new App('./controllersDir', $config);

// controllersDir/IndexController.php
use Redreams\Slim\AbstractController;
use Redreams\Slim\Annotation\Route;

/**
 * @Route("/")
 */
class IndexController extends AbstractController
{
    /**
     * @Route("/")
     * @param Request  $request
     * @param Response $response
     *
     * @return Response
     */
    public function indexAction(Request $request, Response $response): Response
    {
        return $response->write('index:index');
    }

    /**
     * @Route("/test")
     * @param Request  $request
     * @param Response $response
     *
     * @return Response
     */
    public function testAction(Request $request, Response $response): Response
    {
        return $response->write('index:test');
    }

    /**
     * @Route("/getonly", methods={"GET"})
     * @param Request  $request
     * @param Response $response
     *
     * @return Response
     */
    public function getOnlyAction(Request $request, Response $response): Response
    {
        return $response->write('index:getOnly');
    }

    /**
     * @Route("/named", name="namedAction")
     * @param Request  $request
     * @param Response $response
     *
     * @return Response
     */
    public function namedAction(Request $request, Response $response): Response
    {
        return $response->write('index:named');
    }
}