LoginSignup
1
2

More than 5 years have passed since last update.

Debug用 Codeigniter Helper

Last updated at Posted at 2016-05-17
素人の個人的メモ兼、スニペット
勉強も兼ねてますのでコメントとかも感謝です。
(忙しさによっては返信が遅れるかもしれません)

Debug($array);
=>ソースコード内にvar_dumpをコメント表示

Debug($array,'d');
=>ブラウザ上にvar_dumpを < pre > 表示

Debug($array,'p:300','memo');
=>ブラウザ上に縦300pxでprint_fを < pre > で表示

後は作り途中ですがメモ&スニペットとして。

if ( ! function_exists('Debug')){
//$type='300,p' 300=>height p=>print_r
function Debug($datas, $type=null, $hd_mark=null){
  $types = explode(':',$type);

  switch(@$types[0]){

  case 'print_r':
  case 'print':
  case 'p':
    echo "<pre style='overflow:auto; max-height:".@$types[1]."px;'>". $hd_mark. "<br>";
    print_r($datas);
    echo "</pre>";
    break;

  case 'dump':
  case 'd':
    echo "<pre style='overflow:auto; max-height:".@$types[1]."px;'>". $hd_mark. "<br>";
    var_dump($datas);
    echo "</pre>";
    break;

  case 'json':
  case 'j':
    echo json_encode($datas);
    break;

  case 'source':
  case 's':
  case 'html':
  case 'h':
    echo "<!-- Debug: ". ($hd_mark?:"********************************************"). "\n\n";
    var_dump(trim(strip_tags($datas)));
    echo "\n\n******************************************************* -->\n";
    break;

  default:
    echo "<!-- Debug: ". ($hd_mark?:"********************************************"). "\n\n";
    var_dump($datas);
    echo "\n\n******************************************************* -->\n";
  }
}}

1
2
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
1
2