我设法创建了Tablegear模型来处理这个问题
<?php
class Application_Model_Tablegear
{
protected $_name = null;
protected $_username = null;
protected $_password = null;
protected $_estados = null;
protected $_allowDelete = false;
protected $_editable = 'all';
public function allowDelete() {
$this->_allowDelete = true;
return $this;
}
public function setEditable($fields) {
$this->_editable = $fields;
return $this;
}
public function setEstados($estados) {
$this->_estados = $estados;
return $this;
}
public function setDatabase($params) {
$this->_username = $params->username;
$this->_password = $params->password;
$this->_name = $params->dbname;
return $this;
}
public function getOptions() {
return array(
"database" => array(
'username' => $this->_username,
'password' => $this->_password,
'name' => $this->_name,
'table' => "projetos",
'fields' => array(
'pro_cliente',
'pro_area',
'pro_evento',
'estado',
'cidade',
'pro_mes',
'pro_montagem_inicio',
'pro_montagem_fim',
'pro_evento_inicio',
'pro_evento_fim',
'pro_desmontagem_inicio',
'pro_desmontagem_fim',
'pro_atendimento',
'pro_projeto',
'pro_situacao'
)
//"noAutoQuery" => true
),
"selects" => array(
'pro_situacao' => array('Aberto', 'Em Andamento', 'Fechado', 'Cancelado'),
'estado' => $this->_estados
),
"formatting" => array(
'pro_valor' => 'currency[prefix=R$ ,pad]',
'pro_montagem_inicio' => 'date[d/m]',
'pro_montagem_fim' => 'date[d/m]',
'pro_evento_inicio' => 'date[d/m]',
'pro_evento_fim' => 'date[d/m]',
'pro_desmontagem_inicio' => 'date[d/m]',
'pro_desmontagem_fim' => 'date[d/m]'
),
'headers' => array(
'pro_id' => 'ID',
'pro_cliente' => 'Cliente',
'pro_area' => 'Area',
'pro_evento' => 'Evento',
'estado' => 'UF',
'cidade' => 'Cidade',
'pro_mes' => 'Mes',
'pro_montagem_inicio' => 'Inicio Montagem',
'pro_montagem_fim' => 'Fim Montagem',
'pro_evento_inicio' => 'Inicio Evento',
'pro_evento_fim' => 'Fim Evento',
'pro_desmontagem_inicio' => 'Inicio Desmontagem',
'pro_desmontagem_fim' => 'Fim Desmontagem',
'pro_atendimento' => 'Atendimento',
'pro_projeto' => 'Projeto',
'pro_situacao' => 'Situacao',
'pro_valor' => 'Valor',
'DELETE' => 'Deletar'
),
'columns' => array(
'pro_montagem_inicio' => 'date-picker',
'pro_montagem_fim' => 'date-picker',
'pro_evento_inicio' => 'date-picker',
'pro_evento_fim' => 'date-picker',
'pro_desmontagem_inicio' => 'date-picker',
'pro_desmontagem_fim' => 'date-picker'
),
'allowDelete' => $this->_allowDelete,
'editable' => $this->_editable
);
}
}
然后我在控制器中设置方法
$this->tgOptions = new Application_Model_Tablegear();
$this->tgOptions->setDatabase($this->config->resources->db->params)
->setEstados($this->estados->getEstados());