ここを参照:
WordPress:開発用のサーバを作る
WordPressのサイトを立ち上げて、後日、そのサイトのコピーが欲しいとします。 僕はこうしました:
本番側の作業
データベースのバックアップ
mysqldump -u root -p wordpress_production > /tmp/production.dmp
ソースのコピー
(gitに全部入れているので割愛)
コピー側の作業
データベースのリストア
mysql -u root -p -D wordpress_dev < /tmp/production.dmp
URLの変更
mysql -u root -p wordpress_dev mysql> update wp_options set option_value='http://新しいドメイン' where option_name in ('siteurl', 'home');
CakePHP3:フルパスのURLを生成する
結論からいうと、URLヘルパーもしくはRouterの第2引数をtrueに設定します:
URLヘルパーの場合:
$url = $this->Url->build(["controller" => "Posts", "action" => "search", "?" => ["foo" => "bar"] ],true);
ルータの場合:
use Cake\Routing\Router; // これを忘れずに $url = Router::url(['controller' => 'Posts', 'action' => 'search', '?' => ['foo' => $bar] ], true);
これまで$_SERVER["HTTP_HOST"]
とかやってました(汗
Remodal:アンカーを通じて開くことができない
キレイなモーダルを簡単に実装できて重宝しているRemodalですが、アンカーで起動できない現象に遭遇しました:
<div class="remodal" data-remodal-id="my-remodal" data-remodal-options="hashTracking: false"> <button data-remodal-action="close" class="remodal-close"></button> <h1>Remodal</h1> <p> Responsive, lightweight, fast, synchronized with CSS animations, fully customizable modal window plugin with declarative configuration and hash tracking. </p> <br> <button data-remodal-action="cancel" class="remodal-cancel">Cancel</button> <button data-remodal-action="confirm" class="remodal-confirm">OK</button> </div>
<a href="#my-remodal">モーダルを開く</a>
原因はhashTracking: false
の指定でした。これをfalseにすると、モーダルを開いた際に#がつかないため、
ブラウザの閲覧履歴に影響がありません(「戻る」でモーダルが開くのを防げる)
ではどうすればよいかというと、アンカーをこのように書きます:
<a href="#" data-remodal-target="my-remodal">モーダルを開く</a>
ちゃんとドキュメント読まないとダメですね。
CakePHP3:Cannot insert row, some of the primary key values are missing
保存をしても、次のエラーが出ることがあります:
[RuntimeException] Cannot insert row, some of the primary key values are missing. Got (, ), expecting (task_id, user_id)
この場合は該当するEntityを確認し、カラムがaccessibleに含まれているか確認してみてください。
CakePHP3:declare(strict_types=1)の使い所
まだ使い始めて日が浅いですが、ComponentとかHelperのようにいろいろな場所から呼び出しが多いコードは、
必ずdeclare(strict_types=1);
を設定し、かつ、関数の引数と戻り値の型を設定しておくと効率がいい気がします。
あとから設定するのは面倒なので、最初から記述するのがよいかと!