PHP code example of dabl / generator

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

    

dabl / generator example snippets


use Dabl\Generator\DefaultGenerator;
use Dabl\Query\DBManager;

// setup database connection
DBManager::addConnection('test', array(
    'driver' => 'sqlite',
    'dbname' => ':memory:'
));

// create databse tables
$conn = DBManager::getConnection('test');
$conn->exec('CREATE TABLE user (
    id INTEGER,
    name,
    PRIMARY KEY(id ASC)
)');

$conn->exec('CREATE TABLE post (
    id INTEGER,
    user_id INTEGER,
    content,
    PRIMARY KEY(id ASC),
    FOREIGN KEY(user_id) REFERENCES user(id)
)');

$generator = new DefaultGenerator('test');
$generator->generateModels(
    ['user', 'post'],
    './models'
);

$generator->generateViews(
    ['user', 'post'],
    './views'
);

$generator->generateControllers(
    ['user', 'post'],
    './controllers'
);