Skip to content

Commit 716240f

Browse files
authored
Merge pull request #401 from kenjis/fix-docs-install.md
docs: improve install.md
2 parents 2f01a86 + 530d6b2 commit 716240f

File tree

1 file changed

+67
-71
lines changed

1 file changed

+67
-71
lines changed

docs/install.md

Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Installation
22

33
- [Installation](#installation)
4+
- [Requirements](#requirements)
5+
- [Composer Installation](#composer-installation)
46
- [Troubleshooting](#troubleshooting)
5-
- [IMPORTANT: composer error](#important-composer-error)
6-
- [Note: migration error](#note-migration-error)
77
- [Initial Setup](#initial-setup)
88
- [Command Setup](#command-setup)
99
- [Manual Setup](#manual-setup)
@@ -12,8 +12,13 @@
1212

1313
These instructions assume that you have already [installed the CodeIgniter 4 app starter](https://codeigniter.com/user_guide/installation/installing_composer.html) as the basis for your new project, set up your `.env` file, and created a database that you can access via the Spark CLI script.
1414

15-
> **Note**
16-
> CodeIgniter Shield requires Codeigniter v4.2.3 or later.
15+
## Requirements
16+
17+
- [Composer](https://getcomposer.org)
18+
- Codeigniter **v4.2.3** or later
19+
- A created database that you can access via the Spark CLI script
20+
21+
## Composer Installation
1722

1823
Installation is done through [Composer](https://getcomposer.org). The example assumes you have it installed globally.
1924
If you have it installed as a phar, or othewise you will need to adjust the way you call composer itself.
@@ -22,8 +27,6 @@ If you have it installed as a phar, or othewise you will need to adjust the way
2227
> composer require codeigniter4/shield
2328
```
2429

25-
---
26-
2730
### Troubleshooting
2831

2932
#### IMPORTANT: composer error
@@ -37,60 +40,36 @@ If you get the following error:
3740

3841
1. Add the following to change your [minimum-stability](https://getcomposer.org/doc/articles/versions.md#minimum-stability) in your project `composer.json`:
3942

40-
```
41-
"minimum-stability": "dev",
42-
"prefer-stable": true,
43-
```
43+
```json
44+
"minimum-stability": "dev",
45+
"prefer-stable": true,
46+
```
4447

4548
2. Or specify an explicit version:
4649

47-
```
48-
> composer require codeigniter4/shield:dev-develop
49-
```
50-
51-
The above specifies `develop` branch.
52-
See https://getcomposer.org/doc/articles/versions.md#branches
53-
54-
```
55-
> composer require codeigniter4/shield:^1.0.0-beta
56-
```
57-
58-
The above specifies `v1.0.0-beta` or later and before `v2.0.0`.
59-
See https://getcomposer.org/doc/articles/versions.md#caret-version-range-
60-
61-
---
62-
63-
This requires the [CodeIgniter Settings](https://github.com/codeigniter4/settings) package, which uses a database
64-
table to store configuration options. As such, you should run the migrations.
65-
66-
```
67-
> php spark migrate --all
68-
```
69-
70-
---
71-
72-
#### Note: migration error
50+
```console
51+
> composer require codeigniter4/shield:dev-develop
52+
```
7353

74-
When you run `spark migrate --all`, if you get `Class "SQLite3" not found` error:
54+
The above specifies `develop` branch.
55+
See https://getcomposer.org/doc/articles/versions.md#branches
7556

76-
1. Remove sample migration files in `tests/_support/Database/Migrations/`
77-
2. Or install `sqlite3` php extension
57+
```console
58+
> composer require codeigniter4/shield:^1.0.0-beta
59+
```
7860

79-
If you get `Specified key was too long` error:
80-
81-
1. Use InnoDB, not MyISAM.
82-
83-
---
61+
The above specifies `v1.0.0-beta` or later and before `v2.0.0`.
62+
See https://getcomposer.org/doc/articles/versions.md#caret-version-range-
8463

8564
## Initial Setup
8665

8766
### Command Setup
8867

89-
1. Run the following command. This command handles steps 1-4 of *Manual Setup* and runs the migrations.
68+
1. Run the following command. This command handles steps 1-5 of *Manual Setup* and runs the migrations.
9069

91-
```
92-
> php spark shield:setup
93-
```
70+
```console
71+
> php spark shield:setup
72+
```
9473

9574
### Manual Setup
9675

@@ -99,43 +78,60 @@ your project.
9978

10079
1. Copy the `Auth.php` and `AuthGroups.php` from `vendor/codeigniter4/shield/src/Config/` into your project's config folder and update the namespace to `Config`. You will also need to have these classes extend the original classes. See the example below. These files contain all of the settings, group, and permission information for your application and will need to be modified to meet the needs of your site.
10180

102-
```php
103-
// new file - app/Config/Auth.php
104-
<?php
105-
106-
namespace Config;
81+
```php
82+
// new file - app/Config/Auth.php
83+
<?php
10784

108-
// ...
109-
use CodeIgniter\Shield\Config\Auth as ShieldAuth;
85+
namespace Config;
11086

111-
class Auth extends ShieldAuth
112-
{
11387
// ...
114-
}
115-
```
88+
use CodeIgniter\Shield\Config\Auth as ShieldAuth;
89+
90+
class Auth extends ShieldAuth
91+
{
92+
// ...
93+
}
94+
```
11695

11796
2. **Helper Setup** The `setting` helper needs to be included in almost every page. The simplest way to do this is to add it to the `BaseController::initController` method:
11897

119-
```php
120-
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
121-
{
122-
$this->helpers = array_merge($this->helpers, ['setting']);
98+
```php
99+
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
100+
{
101+
$this->helpers = array_merge($this->helpers, ['setting']);
123102

124-
// Do Not Edit This Line
125-
parent::initController($request, $response, $logger);
126-
}
127-
```
103+
// Do Not Edit This Line
104+
parent::initController($request, $response, $logger);
105+
}
106+
```
128107

129-
This requires that all of your controllers extend the `BaseController`, but that's a good practice anyway.
108+
This requires that all of your controllers extend the `BaseController`, but that's a good practice anyway.
130109

131110
3. **Routes Setup** The default auth routes can be setup with a single call in `app/Config/Routes.php`:
132111

133-
```php
134-
service('auth')->routes($routes);
135-
```
112+
```php
113+
service('auth')->routes($routes);
114+
```
136115

137116
4. **Security Setup** Set `Config\Security::$csrfProtection` to `'session'` (or set `security.csrfProtection = session` in your `.env` file) for security reasons, if you use Session Authenticator.
138117

118+
5. **Migration** Run the migrations.
119+
120+
```console
121+
> php spark migrate --all
122+
```
123+
124+
#### Note: migration error
125+
126+
When you run `spark migrate --all`, if you get `Class "SQLite3" not found` error:
127+
128+
1. Remove sample migration files in `tests/_support/Database/Migrations/`
129+
2. Or install `sqlite3` php extension
130+
131+
If you get `Specified key was too long` error:
132+
133+
1. Use InnoDB, not MyISAM.
134+
139135
## Controller Filters
140136

141137
Shield provides 4 [Controller Filters](https://codeigniter.com/user_guide/incoming/filters.html) you can

0 commit comments

Comments
 (0)