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.
Now you can create crap application in minutes
You have to set the minimum-stability
to dev
and then run:
$ composer require malukenho/silex-manager
- twig/twig
- symfony/twig-bridge
- symfony/session
- symfony/form
- symfony/security-csrf
- symfony/translation
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.
$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.
$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' => [],
]);
Router | Bind |
---|---|
/{dbTable}/page/{pageNumber} | manager-index |
/{dbTable}/new | manager-new |
/{dbTable}/edit/{id} | manager-edit |
/{dbTable}/delete/{id} | manager-delete |
You have to put some configuration on $app['manager-config']
to make use
of power from Silex Manager.
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.
$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.
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.
'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;
}
},
Sometimes you will need make a custom query to show data on the list page.
This is possible by setting the key query
.
$app['manager-config'] = [
'manager' => [
'users' => [
'index' => [
'query' => 'SELECT * FROM users u INNER JOIN user_admin ua ON u.id = ua.id',
],
],
],
];
Missing documentation
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.
Missing documentation
Missing documentation
Missing documentation
Missing documentation
Missing documentation