準備
2017年11月25日 公開
2020年05月17日 更新
動作環境
- XAMPP 5.6.31 (Apache 2.4.26, MariaDB 10.1.25, PHP 5.6.31)
- XAMPP インストール先 : 任意のフォルダ (例 C:\XAMPP\xampp_5.6.31) その他 | XAMPP 参照
- IDE (NetBeans IDE 8.2) その他 | Xdebug, NetBeans 参照
サンプルコードの修正
誤 | <a href="<?php echo $base_urlp ?>/user/<?php echo $this->escape($user['user_ name']); ?>"> |
正 | <a href="<?php echo $base_url; ?>/user/<?php echo $this->escape($user['user_name']); ?>"> |
誤 | 'dsn' => 'mysql:dbname=mini_blog;host=localhost', |
正 | 'dsn' => 'mysql:dbname=mini_blog;host=localhost;charset=utf8', |
(PHP 5.3.6 以降)
ドキュメントルート設定
<VirtualHost *:80> ServerName localhost DocumentRoot "C:/XAMPP/xampp_5.6.31/htdocs" DirectoryIndex index.php index.html <Directory "C:/XAMPP/xampp_5.6.31/htdocs"> AllowOverride All Require all granted </Directory> </VirtualHost> <VirtualHost *:80> ServerName mini-blog.localhost DocumentRoot "C:/XAMPP/xampp_5.6.31/htdocs/mini-blog.localhost/web" DirectoryIndex index.php index.html <Directory "C:/XAMPP/xampp_5.6.31/htdocs/mini-blog.localhost"> AllowOverride All Require all granted </Directory> </VirtualHost> |
C:\XAMPP\xampp_5.6.31\apache\conf\extra\httpd-vhosts.conf
hosts ドメイン設定
127.0.0.1 localhost 127.0.0.1 mini-blog.localhost |
C:\Windows\System32\drivers\etc\hosts
データベース
C:\XAMPP\xampp_5.6.31\xampp-control.exe 起動 (Apache, MySQL)
http://localhost/phpmyadmin/ (URL欄)
データベース作成 | mini_blog (utf8_general_ci) (phpMyAdmin) |
テーブル作成用 SQL (サンプルコード内) |
create_table.sql (phpMyAdmin, SQL タブ 選択 mini_blog 上) (C:/XAMPP/xampp_5.6.31/htdocs/mini-blog.localhost) |
テーブル復元用 SQL (テストデータ) |
restore_table.sql (phpMyAdmin, SQL タブ 選択 mini_blog 上) (エラーがある場合) 重要 外部キーのチェックを有効にする: OFF restore_table.sql ダウンロード 動画 (YouTube) パーフェクトPHP をデバッグしました ('フォローする' ボタン を表示) |

テストデータ
テーブル復元用 SQL restore_table.sql ダウンロード (上記 データベース)
id | user_name | password | created_at |
---|---|---|---|
1 | user1 | ee5281d035bd1bd7786301be4274a68b006ae916 | 2017-11-01 00:00:00 |
2 | user2 | ee5281d035bd1bd7786301be4274a68b006ae916 | 2017-11-01 00:00:00 |
3 | user3 | ee5281d035bd1bd7786301be4274a68b006ae916 | 2017-11-01 00:00:00 |
ee5281d035bd1bd7786301be4274a68b006ae916 = 文字列 'password' のハッシュ化
ログイン時、ユーザID: user1、パスワード: password
id | user_id | body | created_at |
---|---|---|---|
1 | 1 | status1 user1 テスト1 | 2017-11-01 00:00:00 |
2 | 1 | status2 user1 テスト2 | 2017-11-01 00:00:00 |
3 | 2 | status3 user2 テスト3 | 2017-11-01 00:00:00 |
4 | 2 | status4 user2 テスト4 | 2017-11-01 00:00:00 |
5 | 3 | status5 user3 テスト5 | 2017-11-01 00:00:00 |
user_id | following_id |
---|---|
1 | 2 |
followingテーブルが空の場合
user1 でログイン後、URL欄に http://mini-blog.localhost/user/user2 を入力すると、user2 の投稿一覧が表示され
'フォローする' ボタンをクリックすると上記データが作成されます