How To Show Data From Database Using PHP CodeIgniter + AngularJS

Hi.. this time I created simple web to show some data from database using PHP CodeIgniter and angularJS. Here is the screenshot of the result page:


I use MySQL as my db. Here is the table that I’ll use for sample:


First of all, I added some angular javascript files to my js folder. Since I use bootstrap for my csss,I added some bootstrap css too to my css folder. Now we ready for codes 🙂

For books_model, I created function to get all books in getAllBooks() function. Continue reading “How To Show Data From Database Using PHP CodeIgniter + AngularJS”

How To Dynamically Set Value On Cells Using PHPExcel

I am quite new coding using PHP. But I’ll try to write simple snap code about how to set value of cell dynamically. You may need it when you have to show some data from query result or any array to XLS / XLSX format. But on this article, I decided using xls format instead.

First of all, put PHPExcel lib to your CI project. You can follow this example. If you are done, then you ready to do the next step.


#.. some code

function doPrintXLSReport($reportDate){
	//load PHPExcel Library
 	$objPHPExcel = new PHPExcel();
	// Set document properties
					 ->setTitle("Sample Report")
					 ->setSubject("Sample Report")
					 ->setDescription("Sample Report")
					 ->setKeywords("Sample Report")
					 ->setCategory("Sample Report");
	//set active sheet and the title. 0 means first sheet that I will use
	$objPHPExcel->getActiveSheet()->setTitle('Sample Report');

	//create style of the cell
	$styleThinBlackBorderOutline = array(
		    'borders' => array(
		        'outline' => array(
		            'style' => PHPExcel_Style_Border::BORDER_THIN,
		            'color' => array('argb' => 'FF000000'),
	//get some data from DB 
	$detail = $this->dbhandler->getTrxDatas($reportDate);

	//set A1 as the first cell
	$current_col = 0;
	$current_row = 1;

		foreach($detail as $det){
			//set value of cell
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($current_col, $current_row, $det['TRX_DATE']);
			//set cell style
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($current_col, $current_row)->applyFromArray($styleThinBlackBorderOutline);
			//move to next column
			//set value and style of the cell
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($current_col, $current_row, $det['TRX_DETAIL']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($current_col, $current_row)->applyFromArray($styleThinBlackBorderOutline);

			//move to next row
			//reset column back to A
			$current_col = 0;

	//do the download process
	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	ob_end_clean() ;
	header('Content-Type: application/');
	header('Content-Disposition: attachment;filename="SampleReport.xls"');
	header('Cache-Control: max-age=0');		 

#.. some code


Hope this simple sample can help. Happy coding 🙂

Penerapan MVC yang Baik dalam Yii Framework


  • Memiliki property sesuai dengan data yang diwakili serta code untuk validasinya.
  • Boleh berisi manipulation code namun tidak boleh memperumit dan memperbesar scala model.
  • Tidak boleh berisi logic yang berhubungan langsung dengan end user seperti penggunaan $_GET, $_POST, atau variabel sejenis yang berhubungan erat dengan request end-user.
  • Menghindari meng-embed HTML atau code presentasional lainnya.


  • Mengandung code presentasional, seperti HTML, dan code PHP sederhana untuk melintasi, memformat dan me-render data.
  • Menghindari code yang melakukan query DB secara langsung.
  • Menghindari akses langsung $_GET, $_POST, atau variabel sejenisnya yang mewakili request end user.
  • Boleh mengakses langsung properti dan method dari controller dan model. Namun, harus dilakukan hanya untuk tujuan presentasi.


  • Boleh mengakses $_GET, $_POST dan variabel PHP lain yang merepresentasikan user request.
  • Membuat berbagai instance model dan mengatur siklus hidupnya.
  • Menghindari menampung statement SQL.
  • Menghindari HTML apapun atau markup presentasional.

How To Generate Code on Yii Framework

First of all, you need to prepare:

  • Yii framework files. You can download from the site
  • Apache.
  • PHP (5.1 or above).

Now we moving forward. The steps are:

  1. Extract yii and put it on folder to your web-accessible root directory. Then check the feature on http://localhost/yii/requirements/ which will be supported with yii on your system. On my computer looks like this:Yii 1
    Yii 2
  2. If you want to using other database, you need set the libs so yii can support the feature. Continue reading “How To Generate Code on Yii Framework”