###前提
MAMP・CakePHP3を使用してHello, worldと表示させたいです。
【スペック】
OS: Mac OS Sierra 10.12.3
MAMP: 4.0.6
###発生している問題・エラーメッセージ
下記エラーメッセージが表示される。
http://localhost:8888/sample/testと入力すると 「Not Found The requested URL /cookbook/test was not found on this server.」と表示される。 またhttp://local:8888/sampleを開くと、デフォルトで表示されるステータス画面のCSSが効いておらず白黒で表示されている。
###ソースコード
lang
1**TestController.php** 2<?php 3 namespace App\Controller; 4 5 use App\Controller\AppController; 6 7 class TestController extends AppController 8 { 9 public function initialize() 10 { 11 //testレイアウトを指定 12 $this->viewBuilder()->layout('test'); 13 } 14 public function index() 15 { 16 //変数teststrをセット 17 $this->set('teststr', 'Hello, World!); 18 19 } 20 } 21?>
lang
1**index.ctp** 2<div> 3 <h1>Helo Wrold!</h1> 4 <p class="text-red"><?= $teststr ?></p> 5</div>
lang
1**test.ctp** 2<!DOCTYPE html> 3<html> 4<head> 5 <?= $this->Html->charset() ?> 6 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 <title> 9 </title> 10 <?= $this->Html->meta('icon') ?> 11 12</head> 13<body> 14 <?= $this->fetch('content') ?> 15 16</body> 17</html>
lang
1routes.php 2Router::defaultRouteClass(DashedRoute::class); 3 4Router::scope('/', function (RouteBuilder $routes) { 5 /** 6 * Here, we are connecting '/' (base path) to a controller called 'Pages', 7 * its action called 'display', and we pass a param to select the view file 8 * to use (in this case, src/Template/Pages/home.ctp)... 9 */ 10 $routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); 11 $routes->connect('/test', ['controller' => 'Test', 'action' => 'index']); //この一行を追加 12 13 /** 14 * ...and connect the rest of 'Pages' controller's URLs. 15 */ 16 $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
###試したこと
ルーティングの設定が間違っているかと思い、route.phpを見返しましたが
間違っていないような気がします。
CSSが効かない事象についてはApacheのhttpd.confの設定が間違っているとの情報を見つけたのでMAMP/conf/apache/httpd.conf内に下記の文言を追記しましたが、CSSは効きませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
PHP7.0.12
あなたの回答
tips
プレビュー