Skip to content

Commit f2bc2dc

Browse files
committed
Functional version
0 parents  commit f2bc2dc

File tree

574 files changed

+86201
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

574 files changed

+86201
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/
2+
composer.lock

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) Jon Segador ([email protected]) / http://crud-admin-generator.com
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
CRUD Admin Generator
2+
===================
3+
4+
What is CRUD Admin Generator?
5+
-----------------------------
6+
7+
**CRUD Admin Generator** ([http://crud-admin-generator.com][1]) is a tool to **generate a complete backend from a MySql database** where you can create, read, update and delete records in a database.
8+
9+
**The backend is generated in seconds** without configuration files where there is a lot of *"magic"* and is very difficult to adapt to your needs.
10+
11+
**The generated code is fully customizable and extensible.**
12+
13+
It has been programmed with the Silex framework, so the resulting code is PHP.
14+
15+
16+
Installation
17+
------------
18+
19+
Clone the repository
20+
21+
git clone [email protected]:jonseg/crud-admin-generator.git admingenerator
22+
23+
cd admingenerator
24+
25+
Download composer:
26+
27+
curl -sS https://getcomposer.org/installer | php
28+
29+
Install vendors:
30+
31+
php composer.phar install
32+
33+
You need point the document root of your virtual host to /path_to/admingenerator/web
34+
35+
36+
Generate CRUD backend
37+
---------------------
38+
39+
Edit the file /path_to/admingenerator/src/app.php and set your database conection data:
40+
41+
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
42+
'dbs.options' => array(
43+
'db' => array(
44+
'driver' => 'pdo_mysql',
45+
'dbname' => 'DATABASE_NAME',
46+
'host' => 'localhost',
47+
'user' => 'DATABASE_USER',
48+
'password' => 'DATABASE_PASS',
49+
'charset' => 'utf8',
50+
),
51+
)
52+
));
53+
54+
55+
Now, execute the command that will generate the CRUD backend:
56+
57+
php console generate:admin
58+
59+
**This is it!** Now access with your favorite web browser.
60+
61+
In the left menu has a section generated by each table in the database that you set. **Now will be much easier to list, create, edit and delete rows!**
62+
63+
64+
Customize the result
65+
--------------------
66+
67+
The generated code is fully configurable and editable, you just have to edit the corresponding files.
68+
69+
The **controller** you can find it in **/web/controllers/TABLE_NAME/index.php**
70+
The **views** are in **/web/views/TABLE_NAME**
71+
72+
It has generated a folder for each table of the database.
73+
74+
75+
Contributing
76+
------------
77+
78+
If you want to contribute code to CRUD Admin Generator, we are waiting for your pull requests!
79+
80+
Some suggestions for improvement could be:
81+
82+
- Different form fields depending on data type.: datetime, time...
83+
- Create admin user with a login and logout page.
84+
- Generate CRUD for tables with more than one primary key.
85+
- Any other useful functionality!
86+
87+
Author
88+
------
89+
90+
* Jon Segador <[email protected]>
91+
* Twitter : *[@jonseg](https://twitter.com/jonseg)*
92+
* Personal blog: *[http://jonsegador.com/](http://jonsegador.com/)*
93+
* CRUD Admin Generator webpage: *[http://crud-admin-generator.com](http://crud-admin-generator.com)*
94+
95+
96+
[1]: http://crud-admin-generator.com

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"require": {
3+
"php": ">=5.3.3",
4+
"silex/silex": "1.2.*",
5+
"monolog/monolog": "~1.4,>=1.4.1",
6+
"doctrine/dbal": "~2.2",
7+
"symfony/console": ">=2.3",
8+
"twig/twig": ">=1.8.0,<2.0-dev",
9+
"symfony/twig-bridge": ">=2.3,<2.6-dev",
10+
"symfony/form": "~2.3",
11+
"symfony/validator": "~2.3",
12+
"symfony/config": "~2.3",
13+
"symfony/translation": "~2.3",
14+
"symfony/locale": "~2.3"
15+
},
16+
"minimum-stability": "dev",
17+
"autoload": {
18+
"psr-0": { "": "src/" }
19+
}
20+
}
21+

console

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
* This file is part of the CRUD Admin Generator project.
6+
*
7+
* Author: Jon Segador <[email protected]>
8+
* Web: http://crud-admin-generator.com
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
require_once __DIR__.'/vendor/autoload.php';
15+
16+
$app = require __DIR__.'/src/app.php';
17+
$console = require __DIR__.'/src/console.php';
18+
$console->run();
19+

gen/base.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the CRUD Admin Generator project.
5+
*
6+
* Author: Jon Segador <[email protected]>
7+
* Web: http://crud-admin-generator.com
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
14+
require_once __DIR__.'/../../vendor/autoload.php';
15+
require_once __DIR__.'/../../src/app.php';
16+
17+
18+
__BASE_INCLUDES__
19+
20+
21+
$app->match('/', function () use ($app) {
22+
23+
return $app['twig']->render('ag_dashboard.html.twig', array());
24+
25+
})
26+
->bind('dashboard');
27+
28+
29+
$app->run();

gen/controller.php

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the CRUD Admin Generator project.
5+
*
6+
* Author: Jon Segador <[email protected]>
7+
* Web: http://crud-admin-generator.com
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
14+
require_once __DIR__.'/../../../vendor/autoload.php';
15+
require_once __DIR__.'/../../../src/app.php';
16+
17+
use Symfony\Component\Validator\Constraints as Assert;
18+
19+
$app->match('/__TABLENAME__', function () use ($app) {
20+
21+
$table_columns = array(
22+
__TABLECOLUMNS_ARRAY__
23+
);
24+
25+
$primary_key = "__TABLE_PRIMARYKEY__";
26+
$rows = array();
27+
28+
$find_sql = "SELECT * FROM `__TABLENAME__`";
29+
$rows_sql = $app['db']->fetchAll($find_sql, array());
30+
31+
foreach($rows_sql as $row_key => $row_sql){
32+
for($i = 0; $i < count($table_columns); $i++){
33+
34+
__EXTERNALS_FOR_LIST__
35+
36+
}
37+
}
38+
39+
return $app['twig']->render('__TABLENAME__/list.html.twig', array(
40+
"table_columns" => $table_columns,
41+
"primary_key" => $primary_key,
42+
"rows" => $rows
43+
));
44+
45+
})
46+
->bind('__TABLENAME___list');
47+
48+
49+
50+
$app->match('/__TABLENAME__/create', function () use ($app) {
51+
52+
$initial_data = array(
53+
__TABLECOLUMNS_INITIALDATA_EMPTY_ARRAY__
54+
);
55+
56+
$form = $app['form.factory']->createBuilder('form', $initial_data);
57+
58+
__EXTERNALSFIELDS_FOR_FORM__
59+
60+
__FIELDS_FOR_FORM__
61+
62+
$form = $form->getForm();
63+
64+
if("POST" == $app['request']->getMethod()){
65+
66+
$form->handleRequest($app["request"]);
67+
68+
if ($form->isValid()) {
69+
$data = $form->getData();
70+
71+
$update_query = "INSERT INTO `__TABLENAME__` (__INSERT_QUERY_FIELDS__) VALUES (__INSERT_QUERY_VALUES__)";
72+
$app['db']->executeUpdate($update_query, array(__INSERT_EXECUTE_FIELDS__));
73+
74+
75+
$app['session']->getFlashBag()->add(
76+
'success',
77+
array(
78+
'message' => '__TABLENAME__ created!',
79+
)
80+
);
81+
return $app->redirect($app['url_generator']->generate('__TABLENAME___list'));
82+
83+
}
84+
}
85+
86+
return $app['twig']->render('__TABLENAME__/create.html.twig', array(
87+
"form" => $form->createView()
88+
));
89+
90+
})
91+
->bind('__TABLENAME___create');
92+
93+
94+
95+
$app->match('/__TABLENAME__/edit/{id}', function ($id) use ($app) {
96+
97+
$find_sql = "SELECT * FROM `__TABLENAME__` WHERE `__TABLE_PRIMARYKEY__` = ?";
98+
$row_sql = $app['db']->fetchAssoc($find_sql, array($id));
99+
100+
if(!$row_sql){
101+
$app['session']->getFlashBag()->add(
102+
'danger',
103+
array(
104+
'message' => 'Row not found!',
105+
)
106+
);
107+
return $app->redirect($app['url_generator']->generate('__TABLENAME___list'));
108+
}
109+
110+
111+
$initial_data = array(
112+
__TABLECOLUMNS_INITIALDATA_ARRAY__
113+
);
114+
115+
116+
$form = $app['form.factory']->createBuilder('form', $initial_data);
117+
118+
__EXTERNALSFIELDS_FOR_FORM__
119+
__FIELDS_FOR_FORM__
120+
121+
$form = $form->getForm();
122+
123+
if("POST" == $app['request']->getMethod()){
124+
125+
$form->handleRequest($app["request"]);
126+
127+
if ($form->isValid()) {
128+
$data = $form->getData();
129+
130+
$update_query = "UPDATE `__TABLENAME__` SET __UPDATE_QUERY_FIELDS__ WHERE `__TABLE_PRIMARYKEY__` = ?";
131+
$app['db']->executeUpdate($update_query, array(__UPDATE_EXECUTE_FIELDS__, $id));
132+
133+
134+
$app['session']->getFlashBag()->add(
135+
'success',
136+
array(
137+
'message' => '__TABLENAME__ edited!',
138+
)
139+
);
140+
return $app->redirect($app['url_generator']->generate('__TABLENAME___edit', array("id" => $id)));
141+
142+
}
143+
}
144+
145+
return $app['twig']->render('__TABLENAME__/edit.html.twig', array(
146+
"form" => $form->createView(),
147+
"id" => $id
148+
));
149+
150+
})
151+
->bind('__TABLENAME___edit');
152+
153+
154+
155+
$app->match('/__TABLENAME__/delete/{id}', function ($id) use ($app) {
156+
157+
$find_sql = "SELECT * FROM `__TABLENAME__` WHERE `__TABLE_PRIMARYKEY__` = ?";
158+
$row_sql = $app['db']->fetchAssoc($find_sql, array($id));
159+
160+
if($row_sql){
161+
$delete_query = "DELETE FROM `__TABLENAME__` WHERE `__TABLE_PRIMARYKEY__` = ?";
162+
$app['db']->executeUpdate($delete_query, array($id));
163+
164+
$app['session']->getFlashBag()->add(
165+
'success',
166+
array(
167+
'message' => '__TABLENAME__ deleted!',
168+
)
169+
);
170+
}
171+
else{
172+
$app['session']->getFlashBag()->add(
173+
'danger',
174+
array(
175+
'message' => 'Row not found!',
176+
)
177+
);
178+
}
179+
180+
return $app->redirect($app['url_generator']->generate('__TABLENAME___list'));
181+
182+
})
183+
->bind('__TABLENAME___delete');
184+
185+
186+
187+
188+
189+

0 commit comments

Comments
 (0)