4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHP3 試してみました

Last updated at Posted at 2015-03-28

先日リリースされたばかりのCakePHP3を触ってみるついでに簡単なシステムを作ってみました。
dev版のときにも一回触ったのですがそのときはbakeしただけなので今回は少しソース触ってみたいと思います。
試作品はGitHubで公開されています。

全体的な印象

ファイルの位置やら命名規則が変わったのは置いておいて、関数自体の変更とかはあまり気にならなかった。
Cake2系ではこう書けばよかったからこうだろ!…ってのは9割方そのまま使えました。この分だと移行はそんなに難しくないかも?

技術的な覚書

実装中にわかった・気付いたことの羅列

PHPタグ

bakeして出されるタグが短縮系になっている。これに合わせたほうがいいのかな

<?= ?>

定数などの位置

debugのOn/OffやDB情報などのCake設定はapp.js
たぶんアプリケーション固有の定数とかはbootstrap.phpに書けばすっきりする。

Migration

Migrationがデフォルトでついてくる。ただし、まだ使いこなせてません。

php cake.php Migrations 

対象カラム

bake後にDBにカラムを追加したときに発見。
ModelのEntityに保存対象にするカラム一覧を更新しないといけない。

/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* @var array
*/
protected $_accessible = [
    'sentence' => true,
    'sort' => true,
    'novel_id' => true,
    'novel' => true,
    'title' => true, // 後から追加
];

Controller関数・変数

Cake2系と同じ使い方でいける関変数

  • $this->layout
  • $this->loadModel()

Paginator

Classを指定できなくなったやつがある?

// $this->Paginator->prev('< ' . __('previous'), ['class' => ['previous']], null, ['class' => ['previous']]) // 2系だとこんな感じ
$this->Paginator->prev('< ' . __('previous'))
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?