SlideShare a Scribd company logo
1 of 17
Rails歴2年(🐥)の私が
Cakeを半年触って
学んだこと
自己紹介
松原愛美
ランサーズ株式会社1年目 CRE
@manamin0521m
学生時代インターンにてRails🐥
2
今日話すこと
2つの言語(フレームワーク)で開発したことで、
それぞれの違いを知る
→ 違いから気づいたことについて
3
CakePHP 1.3→2.8
PHP 5.3
Version
4
言語仕様の違い
1. viewに値を渡す時の違い
Rails
@user = User.find(1)
Cake2.8
$user = $this->User->findById(1);
$this->set(user, $user);
6
「インスタンス変数」の認識の誤りに気づく
◂ Ruby時代は「viewに値を渡せる変数」と認識
◂ 本来はメソッド内のみ使用可という意味
→ オブジェクト指向の理解のきっかけに
7
2. 返り値の理解
Ruby
def plus(num1, num2){
sum = num1 + num2
}
sum = plus(10, 8)
puts '加算の結果は#{ sum }です'
最後に評価された値が返る
※指定することも可能
PHP5.3
function plus($num1, $num2){
$sum = $num1 + $num2;
return $sum;
}
$sum = plus(10, 8);
print '加算の結果は'.$sum.'です';
Returnが必要
8
3. 変数と関数の違い
Ruby
変数
@user = @user.id
関数(メソッド)
Post.test
PHP5.3
変数
$userId = $this->User->id;
関数(メソッド)
$this->Post->test();
9
3. 変数と関数の違いを意識
◂ PHPは関数(メソッド)を使う場合、
引数が空なら()が必要
◂ Ruby時代はピリオドで繋ぎ、直感的に取り出していた
10
配列とオブジェクト
1. 配列の扱い方
Ruby
a = [1, 2, 3]
a.include?(x)
a.empty?
(※Arrayクラス)
PHP
$a = array(1, 2, 3);(※5.3)
$a = [1, 2, 3];(※5.4以降)
in_array( $x, $a );
empty( $a );
12
2. Findした結果が配列かオブジェクトか
Cake2.8
Findした結果が配列
$User['id']
(3以降はオブジェクト)
※オブジェクトから値を
取り出すとき
$user->id
Rails
Findした結果が
オブジェクト
@User.id
13
3. FormからデータをPostした時の処理
Rails
Paramsで受け取る
createメソッドが
オブジェクト化して
オブジェクトをsave
Cake2.8
$this->request->data;
saveメソッドが
配列を引数に取るため
配列をsave
14
4. 複数テーブルを結合して値を取り出す時
Rails
user = User.find(params: id)
@user = user.user_profiles
オブジェクト
Cake2.8
$user = $this->User->find('first', array(
'conditions' => array('User.id' => $id),
'contain' => array('UserProfile')
));
$user[‘UserProfile’];
配列
15
感じたこと
Ruby時代はコピペと感覚で
なんとかなってたけど
PHPは省略できない部分がRubyより多い
違いの理由を学ぶことで勉強になる
複数の言語、フレームワークに触れた方がいいと
言われる理由がわかった
16
ありがとう
ございました!
17

More Related Content

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Rails歴2年の私がCakeを半年触って学んだこと

Editor's Notes

  1. cakeのバージョンはなす PHPのバージョンも話す
  2. Railsはインスタンス変数を使って渡す、 cakeは親クラスであるappにsetメソッドが定義(PHPは変数にドルが絶対必要) Publicで定義してあるのがクラス内変数=インスタンス変数(メンバ変数) (PHP)メソッド内で定義していたらrubyの@をつけない場合と同じ
  3. Userクラスに変数(id)が定義してあるから取れる (ORマッパーではない、modelとかcontrollerの話を出しちゃダメ)
  4. Railsはオブジェクトでクラスを取ってくる、PHPは配列で返す