コード例 #1
0
 public function actionGetword()
 {
     $model = new Challan('search');
     if (isset($_GET['Challan'])) {
         $model->attributes = $_GET['Challan'];
     }
     $data = Challan::model()->findAll();
     header("Content-type: application/vnd.ms-word");
     header("Content-Disposition: attachment;Filename=document_name.doc");
     echo "<html>";
     echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
     echo "<body>";
     echo "<table border='1' width='100%'>";
     if (!empty($_GET['Challan']['fields'])) {
         $fld = $_GET['Challan']['fields'];
     } else {
         $fld = array('challan_number', 'challan_form_number', 'name_person', 'date_fixed', 'vehicle_reg_no', 'scene_of_offence', 'Place of Offence', 'date_time_offence', 'mobile', 'apperance_date', 'fine_amount');
     }
     echo "<tr>";
     foreach ($fld as $d => $v) {
         echo "<th>" . $model->getAttributeLabel($v) . "</th>";
     }
     echo "</tr>";
     foreach ($data as $l => $v) {
         echo "<tr>";
         foreach ((array) $v as $j => $m) {
             foreach ($fld as $d => $val) {
                 if ($val == $j) {
                     echo "<td>{$m}</td>";
                 }
             }
         }
         echo "</tr>";
     }
     echo "</table>";
     echo "</body>";
     echo "</html>";
 }