Skip to content

Instantly share code, notes, and snippets.

@romaninsh
Created January 16, 2017 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romaninsh/b29af2833f6bf8c0517d5b986dd8d37e to your computer and use it in GitHub Desktop.
Save romaninsh/b29af2833f6bf8c0517d5b986dd8d37e to your computer and use it in GitHub Desktop.
A fully-featured web app in 30-lines with Agile UI.
<?php
$app = new \atk4\ui\App('Hello World');
$db = new \atk4\data\Persistence_SQL($dsn);
$app->initLayout('Fluid');
$app->menu->addItem(['Demo1', 'icon'=>'form'], ['demo'=>'form']);
$app->menu->addItem(['Demo2', 'icon'=>'crud'], ['demo'=>'crud']);
$this->layout->add('View', ['view box'])->set('Entire Web APP in 30 lines of code!');
$demo = $app->stickyGET('demo');
if ($demo == 'form') {
$form = $this->layout->add('Form');
$form->setModel(new User($db), ['name', 'email']);
$form->onSubmit(function($form){
$form->model->save();
return 'Created successfully';
});
} elseif ($demo == 'crud') {
$crud = $this->layout->add('CRUD');
$crud->setModel(new User($db));
}
echo $app->render();
class User extends \atk4\data\Model {
function init() {
parent::init();
$this->addField('name');
$this->addField('email', ['type'=>'email']);
$this->addField('created', ['type'=>'datetime', 'default'=>new DateTime()]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment