Skip to content

Instantly share code, notes, and snippets.

@endam
Last active September 22, 2016 02:11
Show Gist options
  • Save endam/0328f9b868a8a645b7d3e7775ff149e7 to your computer and use it in GitHub Desktop.
Save endam/0328f9b868a8a645b7d3e7775ff149e7 to your computer and use it in GitHub Desktop.
出力されたHTMLを見ただけで、CakephpのどのViewの内容なのかすぐに分かるようにする ref: http://qiita.com/endam/items/c8128efc487d027e01d0
<!-- START /var/www/html/sample/app/View/Samples/index.ctp -->
<div>サンプルだよ</div>
<!-- END /var/www/html/sample/app/View/Samples/index.ctp -->
<?= $this->Sample->viewStartComment()?>
<div>サンプルだよ</div>
<?= $this->Sample->viewEndComment()?>
/**
* View開始のHTMLコメント
*/
function viewStartComment()
{
return $this->viewComment();
}
/**
* View終了のHTMLコメント
*/
function viewEndComment()
{
return $this->viewComment(true);
}
/**
* ViewのHTMLコメント出力共通処理
*/
private function viewComment($viewEnd = false)
{
if (env("CAKE_ENV") !== "local"])) {
return "";
}
$debugBackTrace = debug_backtrace();
$viewPath = $debugBackTrace[1]["file"];
$status = $viewEnd ? "END" : "START";
return "<!-- {$status} {$viewPath} -->";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment