cakephp tokyo5
DESCRIPTION
TRANSCRIPT
2010/5/29
CakePHP Study Meetup @tokyo #5
ichikawa
(id:cakephper)
(id:ichikaway)
CakePHP1.3 StableCakePHP1.3 Stable
Self-introductionYasushi Ichikawa Twitter(Japanese): @cakephper Twitter(English): @ichikaway
BlogCakephper diary( CakePHP、MongoDB)
http://d.hatena.ne.jp/cakephper
Self-introduction• I've used the Cakephp since Aug 2008.
• Author of the SQL Explain Component
→ Contributor of the Debug_kit
• Author of the Cakephp MongoDB-Datasource
My code for Cakephphttp://github.com/ichikaway• XformHelper • MongoDB-Datasource• cakeplus
Topic• CakePHP History
• CakePHP1.3 Resources
• CakePHP1.3 New Features
• CakePHP1.3 Migration
CakePHP History
• CakePHP1.2
– Stable Release(2008/12)
• CakePHP1.3
–Stable Release(2010/4)– PHP4, 5
• CakePHP2.0– PHP5.2
CakePHP History• CakePHP1.3 Stable Release(1.5 year)
•Thanks a lot, Cakephp Team!
• Contribution
•Code
•Ticket/Patch
•Document / Translation
•Donation
CakePHP Donation
http://pledgie.com/campaigns/7311
CakePHP Donation
CakePHP DonationEdit profile(paypal email address) after login.
CakePHP Donation
http://pledgie.com/campaigns/7311
CakePHP Donation
寄付は $5以上にした方が良いです。Paypal手数料が差し引かれるので。
CakePHP Donation
CakePHP Donation
Easy, Let's try :)
Topic• CakePHP History
• CakePHP1.3 Resources
• CakePHP1.3 New Features
• CakePHP1.3 Migration
CakePHP1.3 Resources Cakephp Core Code
よく分からない場合はコードを見た方が早い
http://github.com/cakephp/cakephp APIマニュアル
各クラスの説明、メソッドの説明 ここにしか書いていない情報もある http://api.cakephp.org
Cake CookBook Cakeの解説、チュートリアル 英語版と日本語版の不整合に注意 http://book.cakephp.org/view/875/x1-3-Collection
CookBook difference JP/EN
Topic• CakePHP History
• CakePHP1.3 Resources
• CakePHP1.3 New Features
• CakePHP1.3 Migration
CakePHP1.3 New Features• Routes
• Virtual Fields
• Validation
• Bake
• etc
http://book.cakephp.org/ja/view/1572/New-features-in-CakePHP-1-3
CakePHP1.3 New Features• Routes
Prefix Routing
• Adminルーティングと同じ扱いに RouteClass
•ルーティング処理マッチング時に自作クラス呼び出
し
• DBの値を見てマッチング処理を行うなど
–例 1: 該当の slugが DBにあれば routingする
–例 2: urlの一部変更でリダイレクト
CakePHP1.3 New Features
• RouteClass config/routes.php
http://mark-story.com/posts/view/using-custom-route-classes-in-cakephp
App::import('Lib', 'routes/SlugRoute');Router::connect( '/:slug', array('controller' => 'posts', 'action' => 'view'), array('routeClass' => 'SlugRoute'));
CakePHP1.3 New Features• RouteClass
app/libs/routes/slug_route.php
http://mark-story.com/posts/view/using-custom-route-classes-in-cakephp
class SlugRoute extends CakeRoute { function parse($url) { $params = parent::parse($url); App::import('Model', 'Post'); $Post = new Post(); $count = $Post->find('count', array('conditions' =>
array('Post.slug LIKE ?' => $params['slug'] .'%')); if ($count) { return $params;} return false; }}
CakePHP1.3 New Features• Virtual Fields
DBカラムを仮想定義して、 Fieldとして扱えるFieldで表示する内容は SQL文で定義
•例: fullnameカラムに姓名を表示
• 'fullname' => “CONCAT(User.Fname, ' ', User.Lname)”参考:「 VitualFields を使おう!」 hiromi2424さん
• http://d.hatena.ne.jp/hiromi2424/20100204/1265274976
CakePHP1.3 New Features• Validation
マルチバイト対応
• maxLength()などはmb_strlen()を利用
• mb_strlen()が定義されてなければマルチバイトクラ
スのMultibyte::strlen()を利用国別のルールを適用
Phone, postcode, SSN国別のマッチングルールを適用可能例:日本の postcodeなら 222-3333というルール http://github.com/cakephp/localized
CakePHP1.3 New FeaturesValidation
国別のルール適用例// In your ModelApp::import('Lib', 'Localized.JpValidation');class Post extends AppModel { var $validate = array( 'postal' => array( 'valid' => array( 'rule' => array('postal', null, 'jp'), 'message' => '郵便番号が違います ' ) ) );}
CakePHP1.3 New Features• Bake
テンプレート
•コントローラやモデルの雛形を容易にカスタマイズ
–cake/console/templates/default
–例 : 確認画面の処理を含む bakeなど Bake fixture
• Fixtureのみを生成
•ダミーデータや実 DBデータをセット可能
–bake fixture -recordsで実 DBデータセット
CakePHP1.3 New Features• 他にも色々新機能があります
JsHelper
• Jquery, Prototype, Mootoolsを透過的に扱う
–$js->get('#foo')->event('click', $eventCode); Helper::assetTimestamp($path)
• CSSや画像の URLにタイムスタンプ追加 App::import('Lib', 'fooBar');
• imports app/libs/foo_bar.php Validation::ip($someAddress, 'IPv4'); //IPv6もあるよ
CakePHP1.3 New Features
より詳細な情報は New features in CakePHP 1.3参照 CakeBook 11.2 章 付録
日本語 http://book.cakephp.org/ja/view/1572/New-features-in-
CakePHP-1-3 英語
http://book.cakephp.org/view/1572/New-features-in-
CakePHP-1-3
Topic• CakePHP History
• CakePHP1.3 Resources
• CakePHP1.3 New Features
• CakePHP1.3 Migration
CakePHP1.3 Change from 1.2Helper, Componentの自動読み込み廃止
• Session, htmlヘルパー、 Sessionコンポーネントdel()は delete()に
• $this->Session->delete();
• Model->delete();View
• Helper 呼び出し $this->Helper->method()
• $this->element() (renderElement()の廃止 )
• echo $this->Session->flash();
CakePHP1.3 Change from 1.2 タイトル
Controller::pageTitle廃止 $this->set('title_for_layout', $var);
SQLダンプ表示は Layoutに下記必須 <?php echo $this->element('sql_dump'); ?>
Find findAllは、 find('all')に
CakePHP1.3 Change from 1.2• Bootstrap
フォルダ構成を自由に定義可能
• plugin, model, view, controller, datasource, behavior,
component, helper, vendor, shell, locale複数 Path定義可能
App::build(array( 'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'), 'models' => array('/full/path/to/models/', '/next/full/path/to/models/'), 'controllers' => array('/full/path/to/controllers/', '/next/full/path/to/controllers/'), 'behaviors' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'), 'helpers' => array('/full/path/to/helpers/', '/next/full/path/to/helpers/'),));
Migration CakePHP1.2 to 1.3 より詳細な情報はマイグレーションガイドを参照
CakeBookの 11.1 章 付録 英語
http://book.cakephp.org/view/1561/Migrating-from-
CakePHP-1-2-to-1-3
•日本語 http://book.cakephp.org/ja/view/1561/Migrating-
from-CakePHP-1-2-to-1-3 使用しない方が良い /できないメソッド等の一覧 (MASA-
P) http://blog.ecworks.jp/archives/1120
まとめ
• CakePHP History
• CakePHP1.3 Resources
• CakePHP1.3 New Features
–Routes, Model, Validation, Bake
• CakePHP1.3 Migration
–はまったらすぐにマイグレーションガイド
ありがとうございましたありがとうございましたThank youThank you