Created
January 16, 2017 15:40
-
-
Save romaninsh/b29af2833f6bf8c0517d5b986dd8d37e to your computer and use it in GitHub Desktop.
A fully-featured web app in 30-lines with Agile UI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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