示例#1
0
<?php

include dirname(__FILE__) . '/../../inc/header.inc.php';
?>
<div class="list">
<?php 
$theGrid = new Pft_Util_Grid($grid);
$theGrid->addCol('订单ID', 'o_id');
$theGrid->showMe();
?>
</div>
<?php 
include dirname(__FILE__) . '/../../inc/footer.inc.php';
示例#2
0
 /**
  * @param boolean $expressMode
  * @return Pft_Util_Grid
  */
 public function excuteAndReturnGrid($expressMode = false)
 {
     //支持导出报表,如果是导出报表,设置为不使用分页
     if (isset($_REQUEST['searchFormExport']) && $_REQUEST['searchFormExport']) {
         //导出报表
         $this->_usePager = false;
     }
     //			if($this->_sql && isset($_REQUEST['searchFormExport']) && $_REQUEST['searchFormExport']){//导出报表
     //				//导出报表
     //				$file=Pft_Util_Export::ExporttoCsv($datas,"baobiao");
     //				if($file){
     //					$this->_exportfile = $file;
     //				}
     //			}
     Pft_Db::startUseReadonlyDb();
     // 设置“开始使用只读数据库服务器”。Pft_Db 和 Propel 在执行操作时将检测此设置,如果“使用只读数据库”则强制连接到只读数据库服务器
     try {
         if ($this->_sql) {
             //				if($this->_viewandor){
             //
             //					print "<pre>";
             //					print_r($this->_searchs);
             //					print "</pre>";
             //				}
             $this->toPft_Util_Grid_Criteria();
             //这是为了执行 autoGetRequestVar
             $datas = $this->_getAllWithSql();
         } elseif ($this->_omPeerName) {
             if ($expressMode) {
                 $datas = Pft_Util_Array::doSelectPeerToArray($this->_omPeerName, $this->toPft_Util_Grid_Criteria(), $this->_con);
             } else {
                 eval("\$datas = Pft_Util_Array::toArray(" . $this->_omPeerName . "::" . $this->_selectMethod . "(\$this->toPft_Util_Grid_Criteria(), \$this->_con, \$this->_otherParam));");
             }
         }
         if (isset($datas) && is_array($datas)) {
             /**
              * 增加小计
              * @author terry
              * Tue Jun 12 10:49:46 CST 2007
              */
             if (is_array($this->_sumCols) && count($this->_sumCols)) {
                 $rowSum = current($datas);
                 if (is_array($rowSum)) {
                     foreach ($rowSum as $key => $val) {
                         $rowSum[$key] = null;
                     }
                     for ($i = 0; $i < count($datas); $i++) {
                         foreach ($this->_sumCols as $colName) {
                             $rowSum[$colName] += $datas[$i][$colName];
                         }
                     }
                     if ($this->_sumFormat) {
                         foreach ($this->_sumCols as $colName) {
                             $rowSum[$colName] = sprintf($this->_sumFormat, $rowSum[$colName]);
                         }
                     }
                 }
                 $datas[self::DEF_SUM] = $rowSum;
             }
             /**
              * 增加合计
              * 只有Sql模式才提供合计
              * @author terry
              * Tue Jun 12 10:49:54 CST 2007
              */
             if ($this->_sql && is_array($this->_totalCols) && count($this->_totalCols)) {
                 $rowTotal = current($datas);
                 if (is_array($rowTotal)) {
                     foreach ($rowTotal as $key => $val) {
                         $rowTotal[$key] = null;
                     }
                     $totalCols = "";
                     foreach ($this->_totalCols as $colName) {
                         $colName1 = str_replace('+', '_tpma', $colName);
                         $colName1 = str_replace('-', '_tpmb', $colName1);
                         $colName1 = str_replace('*', '_tpmc', $colName1);
                         $colName1 = str_replace('/', '_tpmd', $colName1);
                         $totalCols .= "sum({$colName}) as {$colName1},";
                     }
                     $totalCols = trim($totalCols, ',');
                     $totalSql = str_replace("count(*)", $totalCols, $this->_getCountSql());
                     $rowTotalFromSelect = Pft_Db::getDb()->getRow($totalSql);
                     foreach ($this->_totalCols as $colName) {
                         $colName1 = str_replace('+', '_tpma', $colName);
                         $colName1 = str_replace('-', '_tpmb', $colName1);
                         $colName1 = str_replace('*', '_tpmc', $colName1);
                         $colName1 = str_replace('/', '_tpmd', $colName1);
                         $rowTotal[$colName] = @$rowTotalFromSelect[$colName1];
                     }
                     if ($this->_totalFormat) {
                         foreach ($this->_totalCols as $colName) {
                             $rowTotal[$colName] = sprintf($this->_totalFormat, $rowTotal[$colName]);
                         }
                     }
                 }
                 $datas[self::DEF_TOTAL] = $rowTotal;
             }
         } else {
             //如无 data ,则也无需小计合计
             $datas = array();
         }
         $grid = new Pft_Util_Grid($datas);
         $searchsArray = $this->toArray();
         //增加分组数据
         if ($this->_sql && is_array($this->_searchgroup) && count($this->_searchgroup)) {
             //$searchsArray[self::DEF_SEARCHGROUP] = $this->_searchgroup;
             //$grid->setSearchgroup($this->_searchgroup);
             $searchsArray[self::DEF_SEARCHS][self::DEF_SEARCHGROUP] = $this->_searchgroup;
         }
         //增加导出报表标识
         //生成报表,设置下载
         //			if($this->_sql && isset($_REQUEST['searchFormExport']) && $_REQUEST['searchFormExport']){//导出报表
         //				//导出报表
         //				$file=Pft_Util_Export::ExporttoCsv($datas,"baobiao");
         //				if($file){
         //					$this->_exportfile = $file;
         //				}
         //			}
         $grid->setSearchs($searchsArray[self::DEF_SEARCHS]);
         $grid->setOrderBys($searchsArray[self::DEF_ORDERBYS]);
         if ($this->_usePager) {
             $grid->setPager($searchsArray[self::DEF_PAGERINFO]);
         }
         if ($this->_export) {
             $grid->setExport($this->_export);
         }
         if ($this->_exportfile) {
             $grid->setExportfile($this->_exportfile);
         }
         if ($this->_exportfile_name) {
             $grid->setExportfileName($this->_exportfile_name);
         }
         if ($this->_export_col) {
             $grid->setExportCol($this->_export_col);
         }
         if ($this->_export_format) {
             $grid->setExportFormat($this->_export_format);
         }
         Pft_Db::endUseReadonlyDb();
         // 设置“停止使用只读数据库服务器”
     } catch (Exception $e) {
         Pft_Db::endUseReadonlyDb();
         throw $e;
     }
     return $grid;
 }