Skip to content

Commit 7adf799

Browse files
committed
WIP: boilerplate
1 parent a59aca4 commit 7adf799

File tree

6 files changed

+150
-64
lines changed

6 files changed

+150
-64
lines changed

.github/dashboard.png

93.5 KB
Loading

.github/menu.png

105 KB
Loading

.github/profile.png

98.3 KB
Loading

README.md

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,145 @@
1-
# CodeIgniter 4 Application Starter
1+
2+
CodeIgniter 4 Application Boilerplate
3+
=====================================
4+
![Package](https://img.shields.io/badge/Package-agungsugiarto%2Fboilerplate-light.svg)
5+
[![StyleCI](https://github.styleci.io/repos/243432201/shield?branch=master)](https://github.styleci.io/repos/243432201)
6+
![PHP Composer](https://github.com/agungsugiarto/boilerplate/workflows/PHP%20Composer/badge.svg)
7+
![GitHub All Releases](https://img.shields.io/github/downloads/agungsugiarto/boilerplate/total)
8+
[![GitHub stars](https://img.shields.io/github/stars/agungsugiarto/boilerplate)](https://github.com/agungsugiarto/boilerplate/stargazers)
9+
[![GitHub license](https://img.shields.io/github/license/agungsugiarto/boilerplate)](https://github.com/agungsugiarto/boilerplate/blob/master/LICENSE.md)
10+
11+
Feature
12+
-------
13+
* Configurable backend theme [AdminLTE 3](https://adminlte.io/docs/3.0/)
14+
* Css framework [Bootstrap 4](https://getbootstrap.com/)
15+
* Icons by [Font Awesome 5](https://fontawesome.com/)
16+
* Role-based permissions provided by [Myth/Auth](https://github.com/lonnieezell/myth-auth)
17+
* Menu dynamically
18+
* Localized English / Indonesian
19+
20+
This project is early on development feel free to contribute
21+
------------------------------------------------------------
22+
Screenshoot | Demo On [Heroku](https://boilerplate-codeigniter4.herokuapp.com/)
23+
-------------------------------------------------------------------------------
24+
![Dashboard](.github/dashboard.png?raw=true)
25+
26+
Installation
27+
------------
28+
29+
**1.** Get The Module
30+
31+
require via composer
32+
33+
```bash
34+
composer require agungsugiarto/boilerplate
35+
```
36+
37+
**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.
38+
39+
```bash
40+
# .env file
41+
CI_ENVIRONMENT = development
42+
43+
app.baseURL = 'http://localhost:8080'
44+
app.indexPage = ''
45+
46+
database.default.hostname = localhost
47+
database.default.database = boilerplate
48+
database.default.username = root
49+
database.default.password =
50+
database.default.DBDriver = MySQLi
51+
```
52+
**3.** Run publish auth
53+
```bash
54+
php spark auth:publsih
55+
56+
Publish Migration? [y, n]: n
57+
Publish Models? [y, n]: n
58+
Publish Entities? [y, n]: n
59+
Publish Controller? [y, n]: n
60+
Publish Views? [y, n]: n
61+
Publish Config file? [y, n]: y
62+
created: Config/Auth.php
63+
Publish Language file? [y, n]:
64+
```
65+
66+
> NOTE: Everything about how to configure auth you find add [Myth/Auth](https://github.com/lonnieezell/myth-auth).
67+
68+
69+
Its done ? not to fast. After the publish `Config/Auth.php` you need to change
70+
`public $views` with below like this.
71+
```php
72+
public $views = [
73+
'login' => 'agungsugiarto\boilerplate\Views\Authentication\login',
74+
'register' => 'agungsugiarto\boilerplate\Views\Authentication\register',
75+
'forgot' => 'agungsugiarto\boilerplate\Views\Authentication\forgot',
76+
'reset' => 'agungsugiarto\boilerplate\Views\Authentication\reset',
77+
'emailForgot' => 'agungsugiarto\boilerplate\Views\Authentication\emails\fogot',
78+
'emailActivation' => 'agungsugiarto\boilerplate\Views\Authentication\emails\acivation',
79+
];
80+
```
81+
82+
Open `app\Config\Filters.php` see at `$aliases` add with below like this.
83+
```php
84+
public $aliases = [
85+
'login' => \Myth\Auth\Filters\LoginFilter::class,
86+
'role' => \agungsugiarto\boilerplate\Filters\RoleFilter::class,
87+
'permission' => \agungsugiarto\boilerplate\Filters\PermissionFilter::class,
88+
];
89+
```
90+
91+
**4.** Run publish, migrate and seed boilerplate
92+
93+
```bash
94+
php spark boilerplate:install
95+
```
96+
97+
**5.** Run development server:
98+
99+
```bash
100+
php spark serve
101+
```
102+
103+
**6.** Open in browser http://localhost:8080/admin
104+
```bash
105+
Default user and password
106+
+----+--------+-------------+
107+
| No | User | Password |
108+
+----+--------+-------------+
109+
| 1 | admin | super-admin |
110+
| 2 | user | super-user |
111+
+----+--------+-------------+
112+
```
113+
114+
Settings
115+
--------
116+
117+
Config Boilerplate
118+
119+
You can configure default dashboard controller and backend theme in `app\Config\Boilerplate.php`,
120+
121+
```php
122+
class Boilerplate extends BaseConfig
123+
{
124+
public $appName = 'Boilerplate';
125+
126+
public $dashboard = [
127+
'namespace' => 'agungsugiarto\boilerplate\Controllers',
128+
'controller' => 'DashboardController::index',
129+
'filter' => 'permission:back-office',
130+
];
131+
// App/Config/Boilerplate.php
132+
```
133+
134+
Usage
135+
-----
136+
You can find how its work with the read code routes, controller and views etc. Finnaly happy coding!
137+
138+
Contributing
139+
------------
140+
Contributions are very welcome.
141+
142+
License
143+
-------
144+
145+
This package is free software distributed under the terms of the [MIT license](LICENSE.md).

src/Commands/InstallCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class InstallCommand extends BaseCommand
6262
public function run(array $params)
6363
{
6464
try {
65+
$this->call('boilerplate:publish');
6566
// migrate all first
6667
$this->call('migrate', ['-all']);
6768
// then seed data

src/Commands/PublishCommand.php

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -71,76 +71,17 @@ class PublishCommand extends BaseCommand
7171
public function run(array $params)
7272
{
7373
$this->determineSourcePath();
74-
75-
// Controller
76-
if (CLI::prompt('Publish Controller?', ['y', 'n']) == 'y') {
77-
$this->publishController();
78-
}
79-
80-
// Views
81-
if (CLI::prompt('Publish Views?', ['y', 'n']) == 'y') {
82-
$this->publishViews();
83-
}
84-
85-
// Config
86-
if (CLI::prompt('Publish Config file?', ['y', 'n']) == 'y') {
87-
$this->publishConfig();
88-
}
89-
}
90-
91-
protected function publishController()
92-
{
93-
$path = "{$this->sourcePath}/Controllers/AuthController.php";
94-
95-
$content = file_get_contents($path);
96-
$content = $this->replaceNamespace($content, 'Myth\Auth\Controllers', 'Controllers');
97-
98-
$this->writeFile('Controllers/AuthController.php', $content);
99-
}
100-
101-
protected function publishViews()
102-
{
103-
$map = directory_map($this->sourcePath.'/Views');
104-
$prefix = '';
105-
106-
foreach ($map as $key => $view) {
107-
if (is_array($view)) {
108-
$oldPrefix = $prefix;
109-
$prefix .= $key;
110-
111-
foreach ($view as $file) {
112-
$this->publishView($file, $prefix);
113-
}
114-
115-
$prefix = $oldPrefix;
116-
117-
continue;
118-
}
119-
120-
$this->publishView($view, $prefix);
121-
}
122-
}
123-
124-
protected function publishView($view, string $prefix = '')
125-
{
126-
$path = "{$this->sourcePath}/Views/{$prefix}{$view}";
127-
$namespace = defined('APP_NAMESPACE') ? APP_NAMESPACE : 'App';
128-
129-
$content = file_get_contents($path);
130-
$content = str_replace('agungsugiarto\boilertplate\Views', $namespace.'\Authentication', $content);
131-
132-
$this->writeFile("Views/{$prefix}{$view}", $content);
74+
$this->publishConfig();
13375
}
13476

13577
protected function publishConfig()
13678
{
137-
$path = "{$this->sourcePath}/Config/Auth.php";
79+
$path = "{$this->sourcePath}/Config/Boilerplate.php";
13880

13981
$content = file_get_contents($path);
140-
$content = str_replace('namespace Myth\Auth\Config', 'namespace Config', $content);
141-
$content = str_replace('extends BaseConfig', "extends \Myth\Auth\Config\Auth", $content);
82+
$content = str_replace('namespace agungsugiarto\boilerplate\Config', 'namespace Config', $content);
14283

143-
$this->writeFile('Config/Auth.php', $content);
84+
$this->writeFile('Config/Boilerplate.php', $content);
14485
}
14586

14687
//--------------------------------------------------------------------

0 commit comments

Comments
 (0)