PHP code example of mbarquin / slim-dynamic-routing

1. Go to this page and download the library: Download mbarquin/slim-dynamic-routing 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/ */

    

mbarquin / slim-dynamic-routing example snippets


     $settings = rquin\SlimDR\Factory::slim()
            ->withGroup('api')
            ->withVersionGroup('v1')
            ->withContainer($settings)
            ->withNamespace('\\MyApp\\Controller')
            ->getApp();

    $app->run();

    /**
     * Test Controller file
     * SlimDR example controller
     *
     * PHP version 5.6
     *
     *
     * @category   SlimDR
     * @package    Test
     * @subpackage Controller
     * @author     Moises Barquin Salgado <[email protected]>
     * @copyright  Moises Barquin Salgado 2016
     * @version    GIT: $Id$
     */

    namespace MyApp\Controller;

    use mbarquin\SlimDR\ParentController;

    /**
     * Class test, must implements Controller interface
     * It's extended from mbarquin\SlimDR\Parentcontroller
     */
    class test extends ParentController
    {
        /**
         * Array with actions dependencies, in the form [ method => [dependencies]]
         * @var type
         */
        protected $dependencies = array(
            self::GET => array ('db', 'logger')
        );

        /**
         * GET method as controller action,
         * Params which are not request, reponse and args must be declared on
         * dependencies array.
         *
         * @param Psr\Http\Message\ServerRequestInterface $request  Request object
         * @param Psr\Http\Message\ResponseInterface      $response Reponse object
         * @param array                                   $args     Request params
         * @param \stdClass                               $db       Database object
         * @param \Monolog\Logger                         $logger   Logger object
         */
        public function get($request, $response, $args, \stdClass $db, \Monolog\Logger $logger)
        {
            print_r($args);
        }
    }

    $dependencies = array(
        self::POST => array('dep1', 'db', 'dep3'),
        self::GET  => array('dep1'),
        self::PUT  => array('dep3')
        ...
    );

    $container       = $app->getContainer();

    $container['db'] = function ($c) {
        $db = new stdClass();

        return $db;
    };