CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created DATETIME,
updated DATETIME
);CREATE TABLE bookmarks ( id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
title VARCHAR(50),
description TEXT,
url TEXT,
created DATETIME,
updated DATETIME,
FOREIGN KEY user_key (user_id) REFERENCES users(id));CREATE TABLE tags ( id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255),
created DATETIME,
updated DATETIME,
UNIQUE KEY (title));CREATE TABLE bookmarks_tags ( bookmark_id INT NOT NULL,
tag_id INT NOT NULL,
PRIMARY KEY (bookmark_id, tag_id),
INDEX tag_idx (tag_id, bookmark_id),
FOREIGN KEY tag_key(tag_id) REFERENCES tags(id),
FOREIGN KEY bookmark_key(bookmark_id) REFERENCES bookmarks(id));
#config/app.phpの200行目付近'Datasources'=>['default'=>['className'=>'Cake\Database\Connection','driver'=>'Cake\Database\Driver\Mysql','persistent'=>false,'host'=>'localhost',/* * CakePHP will use the default DB port based on the driver selected * MySQL on MAMP uses port 8889, MAMP users will want to uncomment * the following line and set the port accordingly *///'port' => 'nonstandard_port_number','username'=>'root','password'=>'root','database'=>'bookmarker','encoding'=>'utf8','timezone'=>'UTC','cacheMetadata'=>true,/* * Set identifier quoting to true if you are using reserved words or * special characters in your table or column names. Enabling this * setting will result in queries built using the Query Builder having * identifiers quoted when creating SQL. It should be noted that this * decreases performance because each query needs to be traversed and * manipulated before being executed. */'quoteIdentifiers'=>false,/* * During development, if using MySQL < 5.6, uncommenting the * following line could boost the speed at which schema metadata is * fetched from the database. It can also be set directly with the * mysql configuration directive 'innodb_stats_on_metadata = 0' * which is the recommended value in production environments *///'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],],
スキャッフォルドで色々と生成
おなじみのスキャッフォルド
bookmarkerとしてcakeをインストールしたディレクトリで以下を叩きます
123
php bin/cake.php bake all users
php bin/cake.php bake all bookmarks
php bin/cake.php bake all tags
<?php
namespace App\Model\Entity;use Cake\ORM\Entity;use Cake\Auth\DefaultPasswordHasher;#追記/**
* User Entity.
*/
class User extends Entity {/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* @var array
*/
protected $_accessible=['email'=> true,
'password'=> true,
'bookmarks'=> true,
]; protected function _setPassword($value){#追記$hasher= new DefaultPasswordHasher();#追記return$hasher->hash($valu#追記}}
In CakePHP your application’s domain model gets split into 2 primary object types. The first are repositories or table objects. These objects provide access to collections of data. They allow you to save new records, modify/delete existing ones, define relations, and perform bulk operations. The second type of objects are entities. Entities represent individual records and allow you to define row/record level behavior & functionality.
The folders containing view files now go under src/Template instead of src/View. This was done to separate the view files from files containing php classes (eg. Helpers, View classes).