WebプログラミングV

 目次へ 前へ 次へ

2015/12/21 久米

VCakePHP3

1.CakePHP

1.1 CakePHPとは

(1)はじめに

(2)オブジェクト指向

(3)CakePHPの重要な概念

 

1.2 インストール

(1)インストール事前準備

(2)インストール

バージョン3.0から標準的インストールはComposerを使用するインストールになった。(※最下段参照)
が本授業では、昔ながらのインストール方法で行う。

  1. CakePHP日本語サイトでなく 本家CakePHP英語サイト>MENU>DOWNLOADSから最新版をダウンロードして
  2. 解凍して
  3. フォルダに好きな名前(アプリケーション)を付けて 例 yaoya、petshop、best10、caketest、web3cake
  4. htdocsの中に入れるだけ htdocs/web3/caketest
     
  5. C:\xampp\php\php.iniの中の998行目あたりにある、extension=php_intl.dll の先頭のセミコロン; を外しておく。(国際化用モジュール)
    appache 再起動。

(3)インストールされたフォルダ構成

CakePHPフォルダ構成 太字はアプリケーション開発で主に使用する所

フォルダ  
bin  
config app.php
logs  
plugins  
src Console
Controller
Model
Shell
Template
View
tests  
tmp  
vendor  
webroot cssやjs
   
   
   

※CakePHPのソースはvendor>cakephp>cakephp>srcにあるぞ

 

1.3 アプリケーション開発手順

CakePHP解凍して名前つけたフォルダ名(Cakeディレクトリ)をアプリケーションと呼ぶことにする。 注)正式には何と呼ぶか不明。

  1. phpMyAdminでcakePHP用ユーザとDBを作成。caketestなど
     
  2. configのapp.phpを設定。
    1. DBの設定 →うまく設定できたかチェック http://localhost/アプリケーション/ にアクセス
      'Datasources' => [
      'default' => [
      'username' => 'caketest',
      'password' => '771',
      'database' => 'caketest'
    2. 暗号化時の付与データの設定
      'Security' => [
      'salt' => '585d658c916c90d52e770afa1c385d3f347658d09c21bb778b18d1c8a2fb32ca',←変更
       
  3. テーブル作成。 約束事あり
     
  4. ControllerにxxController作成。 約束事あり
  5. Model>Table>にxxTable.php作成。 約束事あり
  6. Template>テーブル名>にxx.ctp作成。 約束事あり
     
  7. その他レイアウトやcssやjs設定

4〜6を必要な分、行えばアプリケーション完成


 

コラム:Composerによるインストール例

Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\kume>cd C:\xampp\htdocs

C:\xampp\htdocs>composer create-project --prefer-dist cakephp/app web3/caketest
Installing cakephp/app (3.1.2)
  - Installing cakephp/app (3.1.2)
    Loading from cache

Created project in web3/caketest
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing aura/installer-default (1.0.0)
    Loading from cache

  - Installing cakephp/plugin-installer (0.0.12)
    Loading from cache

  - Installing psr/log (1.0.0)
    Loading from cache

  - Installing nesbot/carbon (1.13.0)
    Loading from cache

  - Installing mobiledetect/mobiledetectlib (2.8.17)
    Loading from cache

  - Installing aura/intl (1.1.1)
    Loading from cache

  - Installing ircmaxell/password-compat (v1.0.4)
    Loading from cache

  - Installing cakephp/cakephp (3.1.5)
    Loading from cache

  - Installing symfony/yaml (v2.8.0)
    Loading from cache

  - Installing symfony/filesystem (v3.0.0)
    Loading from cache

  - Installing symfony/config (v2.8.0)
    Loading from cache

  - Installing symfony/polyfill-mbstring (v1.0.0)
    Loading from cache

  - Installing symfony/console (v2.8.0)
    Loading from cache

  - Installing robmorgan/phinx (v0.5.0)
    Loading from cache

  - Installing cakephp/migrations (1.5.1)
    Loading from cache

  - Installing jakub-onderka/php-console-color (0.1)
    Loading from cache

  - Installing jakub-onderka/php-console-highlighter (v0.3.2)
    Loading from cache

  - Installing dnoegel/php-xdg-base-dir (0.1)
    Loading from cache

  - Installing nikic/php-parser (v2.0.0)
    Loading from cache

  - Installing symfony/var-dumper (v3.0.0)
    Loading from cache

  - Installing psy/psysh (v0.6.1)
    Loading from cache

  - Installing jdorn/sql-formatter (v1.2.17)
    Loading from cache

  - Installing cakephp/debug_kit (3.2.2)
    Loading from cache

  - Installing cakephp/bake (1.1.2)
    Loading from cache

symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/process ()
symfony/var-dumper suggests installing ext-symfony_debug ()
psy/psysh suggests installing ext-pcntl (Enabling the PCNTL extension makes PsySH a lot happier :))
psy/psysh suggests installing ext-posix (If you have PCNTL, you'll want the POSIX extension as well.)
psy/psysh suggests installing ext-readline (Enables support for arrow-key history navigation, and showing and manipulating command history.)
psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
cakephp/debug_kit suggests installing ext-sqlite (DebugKit needs to store panel data in a database. SQLite is simple and easy to use.)
Writing lock file
Generating autoload files
> Cake\Composer\Installer\PluginInstaller::postAutoloadDump
> App\Console\Installer::postInstall
Created `config/app.php` file
Set Folder Permissions ? (Default to Y) [Y,n]?
Updated Security.salt value in config/app.php

C:\xampp\htdocs>