diff --git a/.github/dashboard.png b/.github/dashboard.png new file mode 100644 index 0000000..ec94e77 Binary files /dev/null and b/.github/dashboard.png differ diff --git a/.github/menu.png b/.github/menu.png new file mode 100644 index 0000000..18dacd9 Binary files /dev/null and b/.github/menu.png differ diff --git a/.github/profile.png b/.github/profile.png new file mode 100644 index 0000000..396caee Binary files /dev/null and b/.github/profile.png differ diff --git a/README.md b/README.md index a4196da..ccbc162 100644 --- a/README.md +++ b/README.md @@ -1 +1,145 @@ -# CodeIgniter 4 Application Starter \ No newline at end of file + +CodeIgniter 4 Application Boilerplate +===================================== +![Package](https://img.shields.io/badge/Package-agungsugiarto%2Fboilerplate-light.svg) +[![StyleCI](https://github.styleci.io/repos/243432201/shield?branch=master)](https://github.styleci.io/repos/243432201) +![PHP Composer](https://github.com/agungsugiarto/boilerplate/workflows/PHP%20Composer/badge.svg) +![GitHub All Releases](https://img.shields.io/github/downloads/agungsugiarto/boilerplate/total) +[![GitHub stars](https://img.shields.io/github/stars/agungsugiarto/boilerplate)](https://github.com/agungsugiarto/boilerplate/stargazers) +[![GitHub license](https://img.shields.io/github/license/agungsugiarto/boilerplate)](https://github.com/agungsugiarto/boilerplate/blob/master/LICENSE.md) + +Feature +------- +* Configurable backend theme [AdminLTE 3](https://adminlte.io/docs/3.0/) +* Css framework [Bootstrap 4](https://getbootstrap.com/) +* Icons by [Font Awesome 5](https://fontawesome.com/) +* Role-based permissions provided by [Myth/Auth](https://github.com/lonnieezell/myth-auth) +* Menu dynamically +* Localized English / Indonesian + +This project is early on development feel free to contribute +------------------------------------------------------------ +Screenshoot | Demo On [Heroku](https://boilerplate-codeigniter4.herokuapp.com/) +------------------------------------------------------------------------------- +![Dashboard](.github/dashboard.png?raw=true) + +Installation +------------ + +**1.** Get The Module + + require via composer + +```bash +composer require agungsugiarto/boilerplate +``` + +**2.** Set CI_ENVIRONMENT, base url, index page, and database config in your `.env` file based on your existing database (If you don't have a `.env` file, you can copy first from `env` file: `cp env .env` first). If the database not exists, create database first. + +```bash +# .env file +CI_ENVIRONMENT = development + +app.baseURL = 'http://localhost:8080' +app.indexPage = '' + +database.default.hostname = localhost +database.default.database = boilerplate +database.default.username = root +database.default.password = +database.default.DBDriver = MySQLi +``` +**3.** Run publish auth +```bash +php spark auth:publsih + +Publish Migration? [y, n]: n +Publish Models? [y, n]: n +Publish Entities? [y, n]: n +Publish Controller? [y, n]: n +Publish Views? [y, n]: n +Publish Config file? [y, n]: y + created: Config/Auth.php +Publish Language file? [y, n]: +``` + +> NOTE: Everything about how to configure auth you find add [Myth/Auth](https://github.com/lonnieezell/myth-auth). + + +Its done ? not to fast. After the publish `Config/Auth.php` you need to change +`public $views` with below like this. +```php +public $views = [ + 'login' => 'agungsugiarto\boilerplate\Views\Authentication\login', + 'register' => 'agungsugiarto\boilerplate\Views\Authentication\register', + 'forgot' => 'agungsugiarto\boilerplate\Views\Authentication\forgot', + 'reset' => 'agungsugiarto\boilerplate\Views\Authentication\reset', + 'emailForgot' => 'agungsugiarto\boilerplate\Views\Authentication\emails\fogot', + 'emailActivation' => 'agungsugiarto\boilerplate\Views\Authentication\emails\acivation', +]; +``` + +Open `app\Config\Filters.php` see at `$aliases` add with below like this. +```php +public $aliases = [ + 'login' => \Myth\Auth\Filters\LoginFilter::class, + 'role' => \agungsugiarto\boilerplate\Filters\RoleFilter::class, + 'permission' => \agungsugiarto\boilerplate\Filters\PermissionFilter::class, +]; +``` + +**4.** Run publish, migrate and seed boilerplate + +```bash +php spark boilerplate:install +``` + +**5.** Run development server: + +```bash +php spark serve +``` + +**6.** Open in browser http://localhost:8080/admin +```bash +Default user and password ++----+--------+-------------+ +| No | User | Password | ++----+--------+-------------+ +| 1 | admin | super-admin | +| 2 | user | super-user | ++----+--------+-------------+ +``` + +Settings +-------- + +Config Boilerplate + +You can configure default dashboard controller and backend theme in `app\Config\Boilerplate.php`, + +```php +class Boilerplate extends BaseConfig +{ + public $appName = 'Boilerplate'; + + public $dashboard = [ + 'namespace' => 'agungsugiarto\boilerplate\Controllers', + 'controller' => 'DashboardController::index', + 'filter' => 'permission:back-office', + ]; +// App/Config/Boilerplate.php +``` + +Usage +----- +You can find how its work with the read code routes, controller and views etc. Finnaly happy coding! + +Contributing +------------ +Contributions are very welcome. + +License +------- + +This package is free software distributed under the terms of the [MIT license](LICENSE.md). \ No newline at end of file diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index dd9ae1d..cfd20d7 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -62,6 +62,7 @@ class InstallCommand extends BaseCommand public function run(array $params) { try { + $this->call('boilerplate:publish'); // migrate all first $this->call('migrate', ['-all']); // then seed data diff --git a/src/Commands/PublishCommand.php b/src/Commands/PublishCommand.php index 7ee301b..405de15 100644 --- a/src/Commands/PublishCommand.php +++ b/src/Commands/PublishCommand.php @@ -71,76 +71,17 @@ class PublishCommand extends BaseCommand public function run(array $params) { $this->determineSourcePath(); - - // Controller - if (CLI::prompt('Publish Controller?', ['y', 'n']) == 'y') { - $this->publishController(); - } - - // Views - if (CLI::prompt('Publish Views?', ['y', 'n']) == 'y') { - $this->publishViews(); - } - - // Config - if (CLI::prompt('Publish Config file?', ['y', 'n']) == 'y') { - $this->publishConfig(); - } - } - - protected function publishController() - { - $path = "{$this->sourcePath}/Controllers/AuthController.php"; - - $content = file_get_contents($path); - $content = $this->replaceNamespace($content, 'Myth\Auth\Controllers', 'Controllers'); - - $this->writeFile('Controllers/AuthController.php', $content); - } - - protected function publishViews() - { - $map = directory_map($this->sourcePath.'/Views'); - $prefix = ''; - - foreach ($map as $key => $view) { - if (is_array($view)) { - $oldPrefix = $prefix; - $prefix .= $key; - - foreach ($view as $file) { - $this->publishView($file, $prefix); - } - - $prefix = $oldPrefix; - - continue; - } - - $this->publishView($view, $prefix); - } - } - - protected function publishView($view, string $prefix = '') - { - $path = "{$this->sourcePath}/Views/{$prefix}{$view}"; - $namespace = defined('APP_NAMESPACE') ? APP_NAMESPACE : 'App'; - - $content = file_get_contents($path); - $content = str_replace('agungsugiarto\boilertplate\Views', $namespace.'\Authentication', $content); - - $this->writeFile("Views/{$prefix}{$view}", $content); + $this->publishConfig(); } protected function publishConfig() { - $path = "{$this->sourcePath}/Config/Auth.php"; + $path = "{$this->sourcePath}/Config/Boilerplate.php"; $content = file_get_contents($path); - $content = str_replace('namespace Myth\Auth\Config', 'namespace Config', $content); - $content = str_replace('extends BaseConfig', "extends \Myth\Auth\Config\Auth", $content); + $content = str_replace('namespace agungsugiarto\boilerplate\Config', 'namespace Config', $content); - $this->writeFile('Config/Auth.php', $content); + $this->writeFile('Config/Boilerplate.php', $content); } //--------------------------------------------------------------------