본문 바로가기
Programming/CodeIgniter

codeIgniter 어플리케이션에서 firePHP를 사용해서 디버깅 하기.

by 신규하 2009. 8. 12.


firePHP는 firefox에서 사용되는 fireBug의 애드온 입니다. php프로그래밍을 할 때 디버깅을 도와 줍니다.
아래는 요즘 제가 사용하고 있는 codeIgniter에서 firePHP를 사용하는 방법입니다.

준비물.

  1. FireFox : 웹브라우저
  2. fireBug : 부가기능
  3. firePHP : 부가기능
  4. firePHP core library : PHP 라이브러리.


설치

firefox를 설치 하시고 fireBug와 firePHP를 설치해 줍니다.

그러면, 하단에 바퀴벌레 주황색 바퀴벌레 아이콘이 생깁니다. 그 아이콘을 클릭후 Net과 콘솔(Console)을 enable상태로 바꿔 줍니다.

다운 받은 firePHP core library의 압축을 풀어 줍니다. 그리고 system/application/libraries 디렉토리에 FirePHP.class.php파일을 복사 해 주고, 파일의 이름을 firephp.php로 바꿔 줍니다. .


사용법

  • $this->firephp->log($myvariable) : FireBug console에 $myvarriable 값의 덤프를 보냄.
  • $this->firephp->warn($myvariable) : FireBug console에 $myvarriable 값의 덤프를 warning으로 분류해서 보냄.
  • $this->firephp->error($myvariable) : FireBug console에 $myvarriable 값의 덤프를 error으로 분류해서 보냄.


예제

아래와 같은 코드를 넣어 주고 fireBug에서 확인하면 다음과 같이 배열의 값이 보이게 됩니다.
<?php $this->load->library('firephp'); $myvariable = array ( 'language' => 'PHP', 'database' => 'MySQL', 'blogging platform' => 'WordPress', 'post' => 'CodeIgniter and FirePHP', ); $this->firephp->log($myvariable); ?>




특정 IP에서만 firePHP를 사용하기


firePHP의 메시지를 끄려면 $this->firephp->setEnabled(FALSE)를 해 주면 됩니다. 하지만, 특정 IP에서만 firePHP를 사용하고 싶다면 아래와 같은 코드를 넣어 주면 됩니다.
<?php if($this->input->ip_address() =='1.2.3.4') { $this->firephp->setEnabled(TRUE); } else { $this->firephp->setEnabled(FALSE); } ?>

원본 : http://speedtech.it/2009/05/debugging-a-codeigniter-application-with-firephp/

댓글