You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
14
14
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
17
22
18
23
Installation is done through [Composer](https://getcomposer.org). The example assumes you have it installed globally.
19
24
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
22
27
> composer require codeigniter4/shield
23
28
```
24
29
25
-
---
26
-
27
30
### Troubleshooting
28
31
29
32
#### IMPORTANT: composer error
@@ -37,60 +40,36 @@ If you get the following error:
37
40
38
41
1. Add the following to change your [minimum-stability](https://getcomposer.org/doc/articles/versions.md#minimum-stability) in your project `composer.json`:
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-
84
63
85
64
## Initial Setup
86
65
87
66
### Command Setup
88
67
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.
90
69
91
-
```
92
-
> php spark shield:setup
93
-
```
70
+
```console
71
+
> php spark shield:setup
72
+
```
94
73
95
74
### Manual Setup
96
75
@@ -99,43 +78,60 @@ your project.
99
78
100
79
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.
101
80
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
107
84
108
-
// ...
109
-
use CodeIgniter\Shield\Config\Auth as ShieldAuth;
85
+
namespace Config;
110
86
111
-
class Auth extends ShieldAuth
112
-
{
113
87
// ...
114
-
}
115
-
```
88
+
use CodeIgniter\Shield\Config\Auth as ShieldAuth;
89
+
90
+
class Auth extends ShieldAuth
91
+
{
92
+
// ...
93
+
}
94
+
```
116
95
117
96
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:
118
97
119
-
```php
120
-
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
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.
130
109
131
110
3. **Routes Setup** The default auth routes can be setup with a single call in `app/Config/Routes.php`:
132
111
133
-
```php
134
-
service('auth')->routes($routes);
135
-
```
112
+
```php
113
+
service('auth')->routes($routes);
114
+
```
136
115
137
116
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.
138
117
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
+
139
135
## Controller Filters
140
136
141
137
Shield provides 4 [Controller Filters](https://codeigniter.com/user_guide/incoming/filters.html) you can
0 commit comments