Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CakePHP入門 (2006/2/25)
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yusuke Ando
February 25, 2006
Programming
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CakePHP入門 (2006/2/25)
アーカイブです。
第9回PHP勉強会。
Yusuke Ando
February 25, 2006
More Decks by Yusuke Ando
See All by Yusuke Ando
CakePHP3でアプリ開発
yandod
1
430
Shimokita.Unity パーティクルでエフェクト
yandod
0
870
CakePHP3の明るい未来
yandod
1
290
Testing your app with Selenium on Travis CI
yandod
8
3.3k
Testing your app with Selenium on Travis CI
yandod
0
190
Inputで入力を扱う
yandod
0
720
Detonatorで爆発させる勉強会をした報告
yandod
0
2.5k
Mecanimでアニメーション - Shimokita.Unity
yandod
0
790
パリの街をUnityで駆ける
yandod
1
3.5k
Other Decks in Programming
See All in Programming
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
1.3k
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
140
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
220
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
540
RTSPクライアントを自作してみた話
simotin13
0
590
Inside Stream API
skrb
1
690
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2k
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
130
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
220
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
5.5k
Webフレームワークの ベンチマークについて
yusukebe
0
160
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
220
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
200
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Exploring anti-patterns in Rails
aemeredith
3
400
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
250
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Believing is Seeing
oripsolob
1
140
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
190
So, you think you're a good person
axbom
PRO
2
2.1k
Building Applications with DynamoDB
mza
96
7.1k
Transcript
Copyright © YusukeAndo. 2006. All rights reserved. 1 CakePHP入門 PHPでRailsライクな高速開発
PHP勉強会 第9回発表資料 2006年2月25日 安藤祐介
Copyright © YusukeAndo. 2006. All rights reserved. 2 はじめに 巷で話題の“Ruby
On Rails” ! Rubyで実装されたMVCフレームワーク ! 同じ事を繰り返さない - Don’t Repeat Yourself ! 設定よりも規約 - Convention over Configuration ! ActiveRecordによりコードを書かずにDB機能 ! 「高速」開発。(プロトタイプ、改修、運用) →注目度が上昇中 10分で作るRailsアプリ for Windows などの試みが注目されたり・・・
Copyright © YusukeAndo. 2006. All rights reserved. 3 そして Ruby
On RailsのPHP版とも言えるのが・・・ (正確にはRailsライクなフレームワークの中の1つ) なのです
Copyright © YusukeAndo. 2006. All rights reserved. 4 CakePHPの特徴 !
フロントコントローラー、MVCモデル ! 設定不要、サブディレクトリのみで動作可能 ! アクティブレコード、組込みのCRUD ! PHP4、PHP5両対応 「あらゆるレベルのプログラマーにとって快適な環境を」 CakePHP development team
Copyright © YusukeAndo. 2006. All rights reserved. 5 おおまかな構造 アプリケーションのルート
フレームワークのライブラリ 設定ファイル コントローラー モデル ビュー(テンプレート) →以上の構造で丸ごと設置する為、共用型サーバでも容易。
Copyright © YusukeAndo. 2006. All rights reserved. 6 動作の手順 実際に動かしながら触ってみましょ
う!
Copyright © YusukeAndo. 2006. All rights reserved. 7 アーカイブの入手 !
cakephp.orgからアーカイブを入手。 ここです。
Copyright © YusukeAndo. 2006. All rights reserved. 8 セットアップ !
展開して出来たディレクトリを任意にリネーム ! Apacheから見える所にがっつりと設置 ! あとはindex.phpにアクセスすれば動作完了 ※htaccessによるoverride、rewriteが出来るようにしておく Rewriteが使えない場合はcore.php内の設定を修正
Copyright © YusukeAndo. 2006. All rights reserved. 9 画面イメージ データベース設定が無い警告
Copyright © YusukeAndo. 2006. All rights reserved. 10 データベース接続設定 !
データベースへの接続設定を行う ! app/config/database.php に設定を記入 ! ひな型をコピーすると簡単 var $default = array('driver' => 'mysql', 'connect' => 'mysql_pconnect', ‘host’ => ‘localhost’, ホスト名 ‘login’ => ‘user’, ユーザ名 ‘password’ => ‘password’, パスワード ‘database’ => ‘project_name’, DB名 'prefix' => '');
Copyright © YusukeAndo. 2006. All rights reserved. 11 画面イメージ データベース接続成功
Copyright © YusukeAndo. 2006. All rights reserved. 12 テーブル作成 !
データベースにアプリで利用するテーブルを作成 ! 一定のネーミングルールで作成(必須!) ネーミングルール ! テーブル名は複数形英語 (books toys musics …) ! プライマリキーは“id”とする ! 外部キーは“genre_id” “book_id” のように単数_id とする ! “created” “modified”というDATETIMEを作るとベター
Copyright © YusukeAndo. 2006. All rights reserved. 13 画面イメージ コントローラーが無い
作るべきコード
Copyright © YusukeAndo. 2006. All rights reserved. 14 コントローラー作成 /books
にアクセスするとコントローラーが見つからないエラーが・・・ ! エラー画面で指示されたとおりにクラスを作成 app/controllers/%name%_controller.php <?php class BooksController extends AppController { } ?>
Copyright © YusukeAndo. 2006. All rights reserved. 15 モデル作成 今度はモデルが見つからないらしい・・・
! AppModelの派生クラスを作成 app/models/%name%.php <?php class book extends AppModel { } ?>
Copyright © YusukeAndo. 2006. All rights reserved. 16 画面イメージ メソッドが無い
Copyright © YusukeAndo. 2006. All rights reserved. 17 scaffoldの利用 メソッドが無いといわれたが・・・?
! 現段階ではロジックを実装するindex() メソッド等が無い ! Railsにもあるアプリの「骨組み」を提供する機能 ! コントローラーをscaffold指定すれば「骨組み」が利用可能 <?php class BooksController extends AppController { var $scaffold; } ?>
Copyright © YusukeAndo. 2006. All rights reserved. 18 動作確認 !
組込みのCRUDが利用可能です ! Create Read Update Delete の機能 ! マスタのメンテナンス程度であれば十分 ! カラム追加などにも自動で追随する
Copyright © YusukeAndo. 2006. All rights reserved. 19 入力画面 カラムの型に応じた
入力欄を生成
Copyright © YusukeAndo. 2006. All rights reserved. 20 単票形式での表示
Copyright © YusukeAndo. 2006. All rights reserved. 21 カスタマイズ !
組込みのCRUDも便利は便利・・・ ! でもユーザ向けの表示は細かい指定が必要 ! コントローラーを修正し、テンプレートを作ればOK ! scaffoldとの共存もできる
Copyright © YusukeAndo. 2006. All rights reserved. 22 コントローラーの修正 !
app/controllers/%name%_controller.phpにindexメソッド を追加する <?php class BooksController extends AppController { var $scaffold; function index(){ $this->set('data',$this->book->findAll()); } } ?>
Copyright © YusukeAndo. 2006. All rights reserved. 23 テンプレートの作成 !
app/views/%name%/index.thtml を作成 ! Controllerでsetした名前でハッシュがある <table> <tr><th>書名</th><th>登録日</th></tr> <?php foreach ($data as $row): ?> <tr> <td><?php echo $row['book']['title'];?></td> <td><?php echo $row['book']['created'];?></td> </tr> <?php endforeach; ?> </table>
Copyright © YusukeAndo. 2006. All rights reserved. 24 カスタマイズの確認 !
カスタマイズした表示ができました ! scaffoldの機能もURLを叩けば動く(リンクすれば良い) ! リレーションも使えます
Copyright © YusukeAndo. 2006. All rights reserved. 25 画面イメージ モデルに2行程度の修正
で従属データも取得
Copyright © YusukeAndo. 2006. All rights reserved. 26 まとめ !
メリット 簡単セットアップ、スクリプト的な記述 validate、セッション管理も組み込まれている ! デメリット 情報が少ない、マルチバイト関連のノウハウ 習得コストは無いとは言えない
Copyright © YusukeAndo. 2006. All rights reserved. 27 Let‘s Bake! CakePHPなかなか面白そうなフレームワークです。
小回りが利きそうな開発でなら十分に威力を発揮 するのではないでしょうか? 皆さんも今日からBakerです!
Copyright © YusukeAndo. 2006. All rights reserved. 28 謝辞 参考サイト
! 10分で作るCakePHPアプリ for Windows http://p4life.jp/cake/
Copyright © YusukeAndo. 2006. All rights reserved. 29 質疑応答 ご静聴ありがとうございました。