From 432b5b80817f474614d1c4899412bbc97b707fa8 Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Dec 2016 01:15:58 +0800 Subject: [PATCH 1/5] added vlucas/phpdotenv & script `serve` --- composer.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index bae6bbc4..07667d85 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,19 @@ "symfony/validator": "2.5.*", "symfony/config": "2.5.*", "symfony/translation": "2.5.*", - "symfony/locale": "2.5.*" + "symfony/locale": "2.5.*", + "vlucas/phpdotenv": "^2.4" }, "minimum-stability": "dev", + "scripts": { + "post-root-package-install": [ + "php -r \"copy('.env.example', '.env');\"" + ], + "serve": [ + "php -S localhost:8888 -t web" + ] + }, "autoload": { "psr-0": { "": "src/" } } } - From 725b3e181fd483db82894cf1e0eab3e9a1c31e92 Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Dec 2016 01:26:15 +0800 Subject: [PATCH 2/5] added .env.example --- .env.example | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..ed105431 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +DB_DRIVER = pdo_mysql +DB_NAME = DATABASE_NAME +DB_HOST = 127.0.0.1 +DB_USER = DATABASE_USER +DB_PASSWORD = DATABASE_PASS \ No newline at end of file From fa1feb23c54418799a61737f03981d68961c75a4 Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Dec 2016 01:26:33 +0800 Subject: [PATCH 3/5] replaced queryData with _construct, load config from .env file --- src/app.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/app.php b/src/app.php index 3a57a57f..f88722e2 100644 --- a/src/app.php +++ b/src/app.php @@ -16,11 +16,16 @@ class queryData { public $recordsFiltered; public $data; - function queryData() { + function __construct() { } } use Silex\Application; +use Dotenv\Dotenv; + +// fetch config from .env file +$dotenv = new Dotenv(__DIR__.'/..'); +$dotenv->load(); $app = new Application(); @@ -38,11 +43,11 @@ function queryData() { 'dbs.options' => array( 'db' => array( - 'driver' => 'pdo_mysql', - 'dbname' => 'DATABASE_NAME', - 'host' => '127.0.0.1', - 'user' => 'DATABASE_USER', - 'password' => 'DATABASE_PASS', + 'driver' => getenv('DB_DRIVER') ?: 'pdo_mysql', + 'dbname' => getenv('DB_NAME') ?: 'my-db', + 'host' => getenv('DB_HOST') ?: '127.0.0.1', + 'user' => getenv('DB_USER') ?: 'root', + 'password' => getenv('DB_PASSWORD') ?: '', 'charset' => 'utf8', ), ) From 490ab24d32de73b5afafb0168e6c2b4b4de1aa86 Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Dec 2016 01:26:55 +0800 Subject: [PATCH 4/5] ignore .env file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d1502b08..db21c93d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ composer.lock +.env \ No newline at end of file From 0089dcc002d354f45e1a658c4c42034636c68667 Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Dec 2016 01:39:35 +0800 Subject: [PATCH 5/5] updated readme --- README.md | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 1192b4b0..49e7db20 100644 --- a/README.md +++ b/README.md @@ -53,26 +53,13 @@ This is an example of VirtualHost: You can customize the url using the .htaccess file, maybe this will help you: [http://stackoverflow.com/questions/24952846/how-do-i-remove-the-web-from-my-url/24953439#24953439](http://stackoverflow.com/questions/24952846/how-do-i-remove-the-web-from-my-url/24953439#24953439) +Database Configuration +--------------------- +Configuration to connect to database is stored inside `.env` file. If the `.env` file is not in available in root of your project directory, you can rename `.env.example` to `.env` and adjust the value there according to your database. Generate CRUD backend --------------------- -Edit the file /path_to/admingenerator/src/app.php and set your database conection data: - - $app->register(new Silex\Provider\DoctrineServiceProvider(), array( - 'dbs.options' => array( - 'db' => array( - 'driver' => 'pdo_mysql', - 'dbname' => 'DATABASE_NAME', - 'host' => 'localhost', - 'user' => 'DATABASE_USER', - 'password' => 'DATABASE_PASS', - 'charset' => 'utf8', - ), - ) - )); - - You need to set the url of the resources folder. Change this line: @@ -104,6 +91,15 @@ The generated code is fully configurable and editable, you just have to edit the It has generated a folder for each database table. +Serve Using Built-in PHP Server +-------------------- +If you want to serve this project using built-in PHP server, run: `composer run serve`. It will serve the project from localhost:8888. To change the port to something other than 8888, you can edit it inside `composer.json`: + +``` +"serve": [ + "php -S localhost:8888 -t web" +] +``` Contributing ------------