PHP code example of parable-php / framework

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

    

parable-php / framework example snippets


class ConfigPlugin implements PluginInterface
{
    public function __construct(
        protected Config $config
    ) {}

    public function run(): void
    {
        $this->config->setMany([
            'parable' => [
                'default-timezone' => 'Europe/Amsterdam',
                'database' => [
                    'type' => Database::TYPE_MYSQL,
                    'host' => 'localhost',
                    'username' => 'username',
                    'password' => 'password',
                    'database' => 'database',
                    'charSet' => 'utf8mb4',
                    'port' => 40673,
                    // all other values, see https://github.com/parable-php/orm/blob/master/README.md for more
                ],
                'session' => [
                    'enabled' => true,
                    'name' => 'app_session_name',
                ],
                'debug' => [
                    'enabled' => (bool)getenv('DEBUG_ENABLED'),
                    'levels' => E_ALL | ~E_DEPRECATED,
                ],
            ],
            'yourstuff' => [
                'extensions' => [
                    CleanerExtension::class,
                ],
            ],
        ]);
    }
}

class RoutingPlugin implements PluginInterface
{
    public function __construct(
        protected Router $router,
        protected Path $path
    ) {}

    public function run(): void
    {
        $this->router->add(
            ['GET'],
            'site-index',
            '/',
            [SiteController::class, 'indexAction'],
            ['template' => $this->path->getPath('src/Templates/Site/index.phtml')]
        );
    }
}

/** @var \Parable\Framework\Http\Template $this */

public function __construct(protected DataCollection $dataCollection) {}

public function someAction() {
    $this->dataCollection->set('viewData', [
        'value' => 'this is value',
        'bool' => true,    
    ]);
}

echo 'Value is ' . $this->data->get('viewData.value');

$this->router->add(
    ['GET'],
    'api-index',
    '/api',
    static function () {
        echo json_encode([
            'status' => 'success',
        ]);
    },
);
bash
$ composer