『CakePHP』1から3へのVersion UP

今回はCakePHP1からCakePHP3へのバージョンUPに際して、大きく変更となっている箇所をまとめていきたいと思います。
たまたま、このような期会があったため備忘録程度に記載してます。
※記載しているのが全ての変更点ではありません。

公式のマニュアル
CakePHP1→ 【 https://book.cakephp.org/1.3/ja/index.html
CakePHP3→ 【 https://book.cakephp.org/3/ja/index.html

■フォルダ構成

CakePHP1
app
┣config
controllers
models
┣plugins
┣tmp
┣vendors
views
cake
┗VERSION.txt
etc
public_html (DocumentRoot)
vendor
composer.json

CakePHP3
bin
┗cake(migration実行ファイルあり)
config
┗設定ファイル
Logs
┗ログファイル置き場
plugins
src
┣Console
Controller
┣Form
Model
┣Shell
Template (view)
┗View(helper置き場)
tests
tmp
vendor
┗cakephp
┗cakephp
┗VERSION.txt
webroot(DocumentRoot)
composer.json

■Controller

Viewからのnameの値を調べる

CakePHP1
if(isset($this->params[‘form’][‘nameの値’])){

CakePHP3
if(isset($_POST[‘nameの値’])){

Component Ajaxかどうか調べる

CakePHP1
$this->RequestHandler->isAjax()

CakePHP3
$this->request->is(‘ajax’)

DBにデータを新規登録

CakePHP1
$this->Post->create($this->request->data);
$this->Post->save();

CakePHP3
$post = $this->Posts->newEntity($this->request->data);
$this->Posts->save($post);

Sessionの使用方法

CakePHP1
$this->Session->○○()

CakePHP3
$this->request->session()->○○()

Modelオブジェクトの取得

CakePHP1
$posts = ClassRegistry::init(‘posts’);

CakePHP3
$posts = TableRegistry::get(‘posts);

Redirectについて

CakePHP1 
$this->redirect(‘’);があるとそこで処理終了、リダイレクトされる。

CakePHP3
$this->redirect(‘’);があっても後ろの処理も(最後まで)実行された後リダイレクトされる。

■Model

CakePHP1
model sample.php

CakePHP3
Table samplesTable.php
Entity sampleEntity.php

データの取得

CakePHP1
$posts->id = $id;
$post = $posts->read();

CakePHP3
$post = $posts->get($id);

■View

ヘルパーの呼出し

CakePHP1
<?php echo $form->create(‘○○);?>

CakePHP3
<?php echo $this->Form->create(‘○○));?>>

コントローラからの関数名を判定

CakePHP1
<?php if($this->action == ‘edit’):?>

CakePHP3
<?php if($this->request-&g;taction == ‘edit’):?>

—————-
以上、Cake1とCake3での
【フォルダ構成】
【Controller】
【Model】
【View】
についてまとめてみました。