centos7.2 + Apache2.4 + php7 + cakephp3 + mysql5.6 で管理画面を作ります。 その3
centos7.2 + Apache2.4 + php7 + cakephp3 + mysql5.6 で管理画面を作ります。 その3
TOPページをとりあえず作ります。
MVCモデルのControllerを用意します。
$this->render('index');でレンダリングしたいViewを名前を指定する。
デフォルトではアクション名(index)のView(index.ctp)がレンダリングされる。
今回は明示的に指定している。本来は不要。
src/Controller/IndexController.php
<?php namespace App\Controller; use App\Controller\AppController; class IndexController extends AppController { /** * Index method * * @return \Cake\Http\Response|void */ public function index() { //index.ctpをレンダリング $this->render('index'); } }
次にViewを用意する。ファイル名はControllerで指定したindex.ctp。
とりあえず空のviewを作ります。
src/Template/Index/index.ctp
<?php /** * @var \App\View\AppView $this * @var \App\Model\Entity\User[]|\Cake\Collection\CollectionInterface $users */ ?> <a>index</a>
最後にルーティングの設定を変更します。
"/"でアクセスされた場合はデフォルトではPagesのControllerのdisplayのactionを指定している。
これを"/"でアクセスされた場合はIndexのControllerのindexのactionを呼び出すように変更する。
config/routes.php
routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); ↓変更 $routes->connect('/', ['controller' => 'Index', 'action' => 'index']);
これで"/"アクセスした場合に、index.ctpが表示されます。