Silex Manager
, (*1)
Silex Manager is a easy way to create crap CRUD based application.
We know that CRUD based apps is so bad, but It's needed some times., (*2)
Now you can create crap application in minutes, (*3)
, (*4)
Author
Installing
You have to set the minimum-stability to dev and then run:, (*5)
$ composer require malukenho/silex-manager
Requirements
- twig/twig
- symfony/twig-bridge
- symfony/session
- symfony/form
- symfony/security-csrf
- symfony/translation
Usage
First of all, you need to register the ManagerControllerProvider to your Silex\Application.
For now you should pass a PDO instance to the our provider., (*6)
$adapter = new \Manager\Db\Adapter\PdoAdapter($pdo);
$app->mount('/manager', new \Manager\Controller\ManagerControllerProvider($adapter));
When you install the Silex Manager, you don't need to install Silex, because it's already installed.
And all dependencies is installed too. You just want to config this dependencies properly., (*7)
$app->register(new Provider\TwigServiceProvider(), [
// Use this path to load the default views (It's use semantic-ui from CDN)
'twig.path' => __DIR__ . '/vendor/malukenho/silex-manager/views',
]);
$app->register(new Provider\UrlGeneratorServiceProvider());
$app->register(new Provider\SessionServiceProvider());
$app->register(new Provider\ServiceControllerServiceProvider());
$app->register(new Provider\FormServiceProvider());
$app->register(new Provider\ValidatorServiceProvider());
$app->register(new Provider\TranslationServiceProvider(), [
'translator.domains' => [],
]);
Routes
| Router |
Bind |
| /{dbTable}/page/{pageNumber} |
manager-index |
| /{dbTable}/new |
manager-new |
| /{dbTable}/edit/{id} |
manager-edit |
| /{dbTable}/delete/{id} |
manager-delete |
Configurations
You have to put some configuration on $app['manager-config'] to make use
of power from Silex Manager., (*8)
Bellow you can see an example how to make a basic configuration.
Note that users refers to the name of table, and this is including a file
to configure the interface/callbacks/fields., (*9)
$app['manager-config'] = [
// Inside the `manager` key we have config for tables
'manager' => [
'users' => require __DIR__ . '/config/users.php',
],
// Configuration pointing to default view
// You can use your own views
'view' => [
'index' => 'manager-index.twig',
'new' => 'manager-new.twig',
'edit' => 'manager-edit.twig',
],
];
Let's look at the index action on /config/users.php config definition file., (*10)
return [
// List action
'index' => [
// Define columns
// column name on db => label
'columns' => [
'id' => 'Id',
'name' => 'Name',
'email' => 'Email',
],
// Modifies how the colums value is showed up
'modifier' => [
'id' => function (array $data) {
return '#' . $data['id'];
},
],
// Set a primary key name, It's ID by default
'pk' => 'id',
// UI page header
'header' => 'Manager users',
// UI page icon
'icon' => 'user',
// Allow pagination
'pagination' => true,
// Show items per page
'item_per_page' => 10,
// Actions allowed
'action' => [
'new' => 'Create a new user',
'edit' => 'Edit',
'delete' => 'Delete',
],
// Configuration for search field
'search' => [
'input' =>[
[
'name' => 'name',
'placeholder' => 'Find by name',
],
],
'button' => 'Filter'
],
],
];
One interesting thing that you can do when sent a form, is call before, and
after functions, that allows you to execute things before the form is processed and after
it respectively., (*11)
'before' => function (array $data) use ($app) {
if ($app['auth.model']->hasStudentWithMail($data['email'])) {
$app['session']->getFlashBag()->add(
'messageError',
'Email já cadastrado, por favor escolha outro email.'
);
$url = $_SERVER['REQUEST_URI'];
header("Location: {$url}");
exit;
}
},
Custom queries
Sometimes you will need make a custom query to show data on the list page.
This is possible by setting the key query., (*12)
$app['manager-config'] = [
'manager' => [
'users' => [
'index' => [
'query' => 'SELECT * FROM users u INNER JOIN user_admin ua ON u.id = ua.id',
],
],
],
];
Actions
Missing documentation, (*13)
Views
Currently We provide simples views. You can take a look at views folder to implements
your owns presentation files. New presentation files can be configured by follow directive., (*14)
Columns
Missing documentation, (*15)
Before
Missing documentation, (*16)
After
Missing documentation, (*17)
Custom names
Missing documentation, (*18)
Modifiers
Missing documentation, (*19)