LoginSignup
0
0

More than 5 years have passed since last update.

ローカル環境でCakePHPを使ってHello worldを出す

Last updated at Posted at 2018-12-09

OS: Mac
まずは公式サイトからインストール
https://book.cakephp.org/3.0/en/installation.html

なんかプロジェクト名をつける。
ターミナルで bin/cake server コマンド使ってサーバー起動
You must enable the intl extension to use CakePHP ってエラーが出る
PHPにintlって拡張モジュールがなかったみたいだったのでintl をインストール

Mac だとyumよりてbrewコマンドでインストールした方が上手く行くっぽい。
php で intl のインストールが成功したらもう一度公式サイトから CakePHPインストールしたら上手くいった。

指定されたURL、多分http://localhost:8765/ 入力すると初めの画面が出る。

MAMPのローカル環境を使ってたので次はMAMPのhtdogs内にインストールしたCakePHPフォルダを打ち込む

初めの設定として/config/routes.php の
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
 $routes->connect('/test', ['controller' => 'Test', 'action' => 'index']); //★ここを追加!
を追加

次にControllerの設定
/src/Controller/ 内にHelloController.php作成
//HelloController.php
namespace App\Controller;
use App\Controller\AppController;
class HelloController extends AppController {
public function index() {
$this->set("message”,”Helloworld!”);
}
}
追加。

次にTemplateの追加
/src/Template/Test 内にindex.ctpを作成

<?php
//index.ctp
?>


    

Helo Wrold!


    

<?= $teststr ?>



追加。

次にsrc/ViewにHelloを作成してindex.ctp作成
<!DOCTYPE html>




<?php
echo $message;
?>


追加。
とりあえずこんな感じ。

これでHelloworldでるはず。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0