Inclusão de dados pelo Formulário Bom dia, Não consigo gravar dados quando enviado através do formulário. Veja, anexo, video....
ST
Inclusão de dados pelo Formulário  
Bom dia,
Não consigo gravar dados quando enviado através do formulário.
Veja, anexo, video.

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (3)


FC

Posta o código
ST

Segue código do modelo:


<?php/** * Cliente Active Record * @author  <your-name-here> */class Cliente extends TRecord{    const TABLENAME = 'cliente';    const PRIMARYKEY= 'ID';    const IDPOLICY =  'max'; // {max, serial}            private $cidades;    /**     * Constructor method     */    public function __construct($id = NULL, $callObjectLoad = TRUE)    {        parent::__construct($id, $callObjectLoad);        parent::addAttribute('nome');        parent::addAttribute('cidade_id');    }        /**     * Method addCidade     * Add a Cidade to the Cliente     * @param $object Instance of Cidade     */    public function addCidade(Cidade $object)    {        $this->cidades[] = $object;    }        /**     * Method getCidades     * Return the Cliente' Cidade's     * @return Collection of Cidade     */    public function getCidades()    {        return $this->cidades;    }    /**     * Reset aggregates     */    public function clearParts()    {        $this->cidades = array();    }    /**     * Load the object and its aggregates     * @param $id object ID     */    public function load($id)    {            // load the related Cidade objects        $repository = new TRepository('Cidade');        $criteria = new TCriteria;        $criteria->add(new TFilter('cidade_id', '=', $id));        $this->cidades = $repository->load($criteria);            // load the object itself        return parent::load($id);    }    /**     * Store the object and its aggregates     */    public function store()    {        // store the object itself        parent::store();            // delete the related Cidade objects        $criteria = new TCriteria;        $criteria->add(new TFilter('cidade_id', '=', $this->id));        $repository = new TRepository('Cidade');        $repository->delete($criteria);        // store the related Cidade objects        if ($this->cidades)        {            foreach ($this->cidades as $cidade)            {                unset($cidade->id);                $cidade->cidade_id = $this->id;                $cidade->store();            }        }    }    /**     * Delete the object and its aggregates     * @param $id object ID     */    public function delete($id = NULL)    {        $id = isset($id) ? $id : $this->id;        // delete the related Cidade objects        $repository = new TRepository('Cidade');        $criteria = new TCriteria;        $criteria->add(new TFilter('cidade_id', '=', $id));        $repository->delete($criteria);                    // delete the object itself        parent::delete($id);    }}Segue código do formulário:
<?php/** * ClienteForm Registration * @author  <your name here> */class ClienteForm extends TPage{    private $form;    private $datagrid;    private $pageNavigation;    private $loaded;        /**     * Class constructor     * Creates the page and the registration form     */    function __construct()    {        parent::__construct();                // creates the form        $this->form = new TForm('form_Cliente');                try        {            // TUIBuilder object            $ui = new TUIBuilder(500,500);            $ui->setController($this);            $ui->setForm($this->form);                        // reads the xml form            $ui->parseFile('app/forms/clientes.form.xml');                        // get the interface widgets            $fields = $ui->getWidgets();            // look for the TDataGrid object            foreach ($fields as $name => $field)            {                if ($field instanceof TDataGrid)                {                    $this->datagrid = $field;                    $this->pageNavigation = $this->datagrid->getPageNavigation();                }            }                        // add the TUIBuilder panel inside the TForm object            $this->form->add($ui);            // set form fields from interface fields            $this->form->setFields($ui->getFields());        }        catch (Exception $e)        {            new TMessage('error', $e->getMessage());        }                // add the form to the page        parent::add($this->form);    }        /**     * method onSave()     * Executed whenever the user clicks at the save button     */    function onSave()    {        try        {            // open a transaction with database 'teste'            TTransaction::open('teste');                        // get the form data into an active record Cliente            $object = $this->form->getData('Cliente');                        // form validation            $this->form->validate();                        // stores the object            $object->store();                        // set the data back to the form            $this->form->setData($object);                        // close the transaction            TTransaction::close();                        // shows the success message            new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));            // reload the listing        }        catch (Exception $e) // in case of exception        {            // shows the exception error message            new TMessage('error', '<b>Error</b> ' . $e->getMessage());            // undo all pending operations            TTransaction::rollback();        }    }    /**     * method onEdit()     * Executed whenever the user clicks at the edit button da datagrid     */    function onEdit($param)    {        try        {            if (isset($param['key']))            {                // get the parameter $key                $key=$param['key'];                                // open a transaction with database 'teste'                TTransaction::open('teste');                                // instantiates object Cliente                $object = new Cliente($key);                                // fill the form with the active record data                $this->form->setData($object);                                // close the transaction                TTransaction::close();            }            else            {                $this->form->clear();            }        }        catch (Exception $e) // in case of exception        {            // shows the exception error message            new TMessage('error', '<b>Error</b> ' . $e->getMessage());                        // undo all pending operations            TTransaction::rollback();        }    }}</your>
ST