質問編集履歴
1
routes.phpについてと、URLパスについて更新させていただきました。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
cakephpの
|
1
|
+
cakephpで認証したら他のページにアクセスできない。
|
body
CHANGED
@@ -14,6 +14,11 @@
|
|
14
14
|
you are not authorized to access that location
|
15
15
|
と表示されて、もとのusersページに移されてしまいます。
|
16
16
|
|
17
|
+
具体的には
|
18
|
+
C/xampp/htdocs/cake/src/Controller/UsersController(localhost/cake/Users/index)にはアクセスできますが
|
19
|
+
C/xampp/htdocs/cake/src/Controller/HomeController(localhost/cake/Home/index)や
|
20
|
+
localhost/cake/index.php(一番最初のデータベースがつながったかどのデータベース)にアクセスできません。
|
21
|
+
|
17
22
|
### 該当のソースコード
|
18
23
|
|
19
24
|
|
@@ -193,8 +198,93 @@
|
|
193
198
|
}
|
194
199
|
|
195
200
|
|
201
|
+
routes.php
|
202
|
+
|
196
203
|
```
|
204
|
+
<?php
|
205
|
+
/**
|
206
|
+
* Routes configuration
|
207
|
+
*
|
208
|
+
* In this file, you set up routes to your controllers and their actions.
|
209
|
+
* Routes are very important mechanism that allows you to freely connect
|
210
|
+
* different URLs to chosen controllers and their actions (functions).
|
211
|
+
*
|
212
|
+
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
213
|
+
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
214
|
+
*
|
215
|
+
* Licensed under The MIT License
|
216
|
+
* For full copyright and license information, please see the LICENSE.txt
|
217
|
+
* Redistributions of files must retain the above copyright notice.
|
218
|
+
*
|
219
|
+
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
220
|
+
* @link https://cakephp.org CakePHP(tm) Project
|
221
|
+
* @license https://opensource.org/licenses/mit-license.php MIT License
|
222
|
+
*/
|
197
223
|
|
224
|
+
use Cake\Core\Plugin;
|
225
|
+
use Cake\Routing\RouteBuilder;
|
226
|
+
use Cake\Routing\Router;
|
227
|
+
use Cake\Routing\Route\DashedRoute;
|
228
|
+
|
229
|
+
/**
|
230
|
+
* The default class to use for all routes
|
231
|
+
*
|
232
|
+
* The following route classes are supplied with CakePHP and are appropriate
|
233
|
+
* to set as the default:
|
234
|
+
*
|
235
|
+
* - Route
|
236
|
+
* - InflectedRoute
|
237
|
+
* - DashedRoute
|
238
|
+
*
|
239
|
+
* If no call is made to `Router::defaultRouteClass()`, the class used is
|
240
|
+
* `Route` (`Cake\Routing\Route\Route`)
|
241
|
+
*
|
242
|
+
* Note that `Route` does not do any inflections on URLs which will result in
|
243
|
+
* inconsistently cased URLs when used with `:plugin`, `:controller` and
|
244
|
+
* `:action` markers.
|
245
|
+
*
|
246
|
+
* Cache: Routes are cached to improve performance, check the RoutingMiddleware
|
247
|
+
* constructor in your `src/Application.php` file to change this behavior.
|
248
|
+
*
|
249
|
+
*/
|
250
|
+
Router::defaultRouteClass(DashedRoute::class);
|
251
|
+
|
252
|
+
Router::scope('/', function (RouteBuilder $routes) {
|
253
|
+
/**
|
254
|
+
* Here, we are connecting '/' (base path) to a controller called 'Pages',
|
255
|
+
* its action called 'display', and we pass a param to select the view file
|
256
|
+
* to use (in this case, src/Template/Pages/home.ctp)...
|
257
|
+
*/
|
258
|
+
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
|
259
|
+
|
260
|
+
/**
|
261
|
+
* ...and connect the rest of 'Pages' controller's URLs.
|
262
|
+
*/
|
263
|
+
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
|
264
|
+
|
265
|
+
/**
|
266
|
+
* Connect catchall routes for all controllers.
|
267
|
+
*
|
268
|
+
* Using the argument `DashedRoute`, the `fallbacks` method is a shortcut for
|
269
|
+
* `$routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);`
|
270
|
+
* `$routes->connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);`
|
271
|
+
*
|
272
|
+
* Any route class can be used with this method, such as:
|
273
|
+
* - DashedRoute
|
274
|
+
* - InflectedRoute
|
275
|
+
* - Route
|
276
|
+
* - Or your own route class
|
277
|
+
*
|
278
|
+
* You can remove these routes once you've connected the
|
279
|
+
* routes you want in your application.
|
280
|
+
*/
|
281
|
+
$routes->fallbacks(DashedRoute::class);
|
282
|
+
});
|
283
|
+
|
284
|
+
```
|
285
|
+
|
286
|
+
```
|
287
|
+
|
198
288
|
### 試したこと
|
199
289
|
|
200
290
|
考えている原因として、
|
@@ -205,4 +295,10 @@
|
|
205
295
|
|
206
296
|
### 補足情報(FW/ツールのバージョンなど)
|
207
297
|
|
208
|
-
cakephp3
|
298
|
+
cakephp3
|
299
|
+
|
300
|
+
### 追記
|
301
|
+
|
302
|
+
申し訳ありません。
|
303
|
+
routes.phpというものが大事だったのですね。
|
304
|
+
routes.phpを書き換えれば、Usersコントローラーの認証は関係なくなるのでしょうか。
|