PHP code example of shubinmi / ant-framework-php

1. Go to this page and download the library: Download shubinmi/ant-framework-php 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/ */

    

shubinmi / ant-framework-php example snippets




use Ant\Application\Application;

// Define paths of folders with configuration files
$configDirs = [
    'Config/Production'
];
if (defined('APPLICATION_ENV') && APPLICATION_ENV == 'local') {
    $configDirs[] = 'Config/Local';
}

$app = new Application();
$app->loadConfig($configDirs);
$app->run();



return [
    'router' => [
        'main'                   => [
            ['GET', 'POST'], '/[{msg}[/]]', [
                'controller' => 'Controllers\Main',
                'action'     => 'mainAction'
            ]
        ]
     ]
]



return [
    'router' => [
        // This will be rewriting rulles for path with 'main' key at Production folder
        'main'                   => [
            ['GET', 'POST'], '/[{msg}[/]]', [
                'controller' => 'Controllers\Main',
                'action'     => 'mainAction'
            ]
        ]
     ]
]



namespace Controllers;

use Ant\Application\Controller;
use Ant\Application\View;

class Main extends Controller
{
    public function mainAction()
    {
        $msg = $this->getRequestUriParam('msg');
        $elements = [
            // It mean that {{body}} at layout.phtml (and at other view elements) will be 
            // replaced to content from main.phtml
            'body' => [
                'path' => 'Views/main.phtml',
                'vars' => ['msg' => $msg]
            ]
        ];
        
        return $this->getView()->addLayoutElements($elements);
    }
    
    private function getView()
    {
        $view = new View();
        $view->setLayoutPath('Views/layout.phtml');
        
        return $view;
    }
}


Your message = "

    /** @var string|null $msg */
    echo $msg;
bash
$ composer