PD
erros list
Fechado
fui listar um forncedor e me de o seruinte erro,
mesmo usando o metodo _toString retornando o neme o erro continua
controller
fornecedor
mesmo usando o metodo _toString retornando o neme o erro continua
controller
- <?php
- /**
- * ProdutoList Listing
- * @author <your name here>
- */
- class ProdutoList extends TStandardList
- {
- protected $form; // registration form
- protected $datagrid; // listing
- protected $pageNavigation;
- /**
- * Class constructor
- * Creates the page, the form and the listing
- */
- public function __construct()
- {
- parent::__construct();
- // defines the database
- parent::setDatabase('sample');
- // defines the active record
- parent::setActiveRecord('Produto');
- // defines the filter field
- parent::setFilterField('nome');
- // creates the form
- $this->form = new TForm('form_search_Produto');
- // creates a table
- $table = new TTable;
- // add the table inside the form
- $this->form->add($table);
- // create the form fields
- $filter = new TEntry('nome');
- $filter->setValue(TSession::getValue('Produto_nome'));
- // add a row for the filter field
- $row=$table->addRow();
- $row->addCell(new TLabel('nome:'));
- $row->addCell($filter);
- // create two action buttons to the form
- $find_button = new TButton('find');
- $new_button = new TButton('new');
- // define the button actions
- $find_button->setAction(new TAction(array($this, 'onSearch')), _t('Find'));
- $find_button->setImage('ico_find.png');
- $new_button->setAction(new TAction(array('ProdutoForm', 'onEdit')), _t('New'));
- $new_button->setImage('ico_new.png');
- // add a row for the form actions
- $row=$table->addRow();
- $row->addCell($find_button);
- $row->addCell($new_button);
- // define wich are the form fields
- $this->form->setFields(array($filter, $find_button, $new_button));
- // creates a DataGrid
- $this->datagrid = new TQuickGrid;
- $this->datagrid->setHeight(320);
- // creates the datagrid columns
- 767 = $this->datagrid->addQuickColumn('id', 'id', 'right', 100);
- $nome = $this->datagrid->addQuickColumn('nome', 'nome', 'left', 200);
- $descricao = $this->datagrid->addQuickColumn('descricao', 'descricao', 'left', 200);
- $preco = $this->datagrid->addQuickColumn('preco', 'preco', 'left', 200);
- $fornecedor_id = $this->datagrid->addQuickColumn('fornecedor', 'fornecedor', 'right', 100);
- // add the actions to the datagrid
- $this->datagrid->addQuickAction(_t('Edit'), new TDataGridAction(array('ProdutoForm', 'onEdit')), 'id', 'ico_edit.png');
- $this->datagrid->addQuickAction(_t('Delete'), new TDataGridAction(array($this, 'onDelete')), 'id', 'ico_delete.png');
- // create the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- // creates the page structure using a table
- $table = new TTable;
- $table->addRow()->addCell($this->form);
- $table->addRow()->addCell($this->datagrid);
- $table->addRow()->addCell($this->pageNavigation);
- // add the table inside the page
- parent::add($table);
- }
- }
- ?>
fornecedor
- <?php
- /**
- * Fornecedor Active Record
- * @author <your-name-here>
- */
- class Fornecedor extends TRecord
- {
- const TABLENAME = 'tblFornecedor';
- const PRIMARYKEY= 'id';
- const IDPOLICY = 'max'; // {max, serial}
- /**
- * Constructor method
- */
- public function __construct(767 = NULL)
- {
- parent::__construct(767);
- parent::addAttribute('razaoSocial');
- parent::addAttribute('cnpj');
- parent::addAttribute('responsavel');
- parent::addAttribute('telefone');
- parent::addAttribute('cep');
- parent::addAttribute('rua');
- parent::addAttribute('bairro');
- parent::addAttribute('cidade');
- parent::addAttribute('uf');
- parent::addAttribute('numero');
- }
- public function __toString(){
- return $this->razaoSocial;
- }
- }
- ?>
Oi Alexandre,
Você mandou listar da classe Produto, o atributo Fornecedor, que é um objeto TRecord. Somente componentes (classes que implementam IWidget), podem ser acrescentadas na datagrid. Se você quiser exibir o nome do fornecedor, use na datagrid "fornecedor_nome" e crie um método get_fornecedor_nome().
PS: Na próxima versão, você poderá usar na datagrid "fornecedor->nome". O que ficará bem melhor.
abraços,
Pablo