PHP code example of nagyatka / kodiapp

1. Go to this page and download the library: Download nagyatka/kodiapp 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/ */

    

nagyatka / kodiapp example snippets


/*
 * index.php
 */

define('PATH_BASE', dirname(__FILE__).'/..' );

// Composer autoloader
w MyAppConfiguration());

class MyAppConfiguration implements ApplicationConfiguration
{
    public function __construct()
    {
        // ...
    }

    public function initializeApplication(Application $application)
    {
        // ...
    }
}

//Struktúra:    
    [route_name] => [
        "method"    =>  [HTTP method],
        "url"       =>  [url],
        "handler"   =>  "[controller_class]::[controller_class_function]",
    ], ...
    
//Példa:
    "home" => [
        "method"    =>  "GET",
        "url"       =>  "/",
        "handler"   =>  "HomeController::handleIndex",
    ],

class MyAppConfiguration implements ApplicationConfiguration
{
    private $myroutes = [
         "home" => [
                "method"    =>  "GET",
                "url"       =>  "/",
                "handler"   =>  "HomeController::handleIndex",
         ],  
    ];
    
    public function initializeApplication(Application $application)
    {
        $router = new SimpleRouter();
        $router->setRoutes($this->myroutes);
        $application->setRouter($router);
    }
}

class HomeController 
{
    public function handleIndex()
    {
        return "Hello world!";
    }
}

class MyAppConfiguration implements ApplicationConfiguration
{
    private $myroutes = [
         "home" => [
                "method"    =>  "GET",
                "url"       =>  "/user/{user_id:[0-9]+}",
                "handler"   =>  "UserController::getUser",
         ],  
    ];
    
    public function initializeApplication(Application $application)
    {
        $router = new SimpleRouter();
        $router->setRoutes($this->myroutes);
        $application->setRouter($router);
    }
}

class UserController 
{
    public function getUser($params)
    {
        return "User_id: ".$params["user_id"];
    }
}