How to save data through Model?

0

My difficulty with the MVC standard is how calls work. For example, I'm working on a form:

<form action="">

    <label>Paciente:</label>
    <input type="text" name="usu_nome" id="usu_nome" value="" class="focus" onkeypress="buscaParticipante()" />
    <input type="hidden" name="usu_codigo" id="usu_codigo" value="" />
    <!-- Informações ocultas para atualização dos dados do cidadão -->
    <input type="hidden" name="id_nome" id="id_nome" value="usu_nome" />
    <input type="hidden" name="id_codigo" id="id_codigo" value="usu_codigo" />
    <input type="hidden" name="id_data" id="id_data" value="" />
    <input type="hidden" name="id_button" id="id_button" value="" />
    <input type="hidden" name="id_tipo" id="id_tipo" value="A" />
    <br/>


    <div id="escondida" <?($this->dados_sessao[usr_codigo_medico] ? "" : "style='display: none'")?> >
    <label>Profissional:</label>
    <input type="text" id="usr_nome" name="usr_nome" value="<?=$this->dados_sessao[usr_nome]?>" onkeypress="mostraMedico()" />
    <input type="hidden" id="usr_codigo" name="usr_codigo_medico" value="<?=$this->dados_sessao[usr_codigo_medico]?>" />
    <input type="hidden" id="interno" name="interno" value="<?=$this->dados_sessao[interno]?>" style="width: 20px" />
    <input type="hidden" name="esp_codigo_selecionado" id="esp_codigo" value="<?=$this->dados_sessao[esp_codigo_selecionado]?>" />
    <br />
    </div>


    <label style="width: 110px;">Unidade:</label>
    <input type="text" name="uni_desc" id="uni_desc" tabindex="1" value="<?= $this->dados->uni_desc ? $this->dados->uni_desc : $this->uni_desc_controle ?>" onkeypress="buscaUnidade()"/>
    <input type="hidden" name="uni_codigo" id="uni_codigo"
           value="<?= $this->dados->uni_codigo ? $this->dados->uni_codigo : $this->uni_codigo_controle ?>">
    <br/>

    <label>Peso <small>(Kg)</small>:</label>
    <input type="text" name="peso" value="<?= $this->dados->pc_peso?(number_format($this->dados->pc_peso,3)):""; ?>"class="float" rel="3,3" <?=($this->vizualizar == 1 ? "disabled" : "")?> />
    <br />


    <label>Altura <small>(m)</small>:</label>
    <input type="text" name="altura" value="<?= $this->dados->pc_altura?(number_format($this->dados->pc_altura,2)):""; ?>"class="float" rel="1,2" <?=($this->vizualizar == 1 ? "disabled" : "")?> /><br />


    <table class='tb_cids' style='margin-bottom: 2px width: 487px border: 1px solid border-color: #CDDEF2'' border='0'>
        <div id='erro'></div>
    </table>

    <label>Anamnese:</label>
    <div class="textarea">
        <textarea name="anamnese" class="tinymce" <?=($this->vizualizar == 1 ? "disabled" : "")?>><?= $this->escape($this->dados->pc_dados); ?></textarea>
    </div>


     Preenchido por : <select id="preenchidoPor" name="preenchidoPor">
        <option>Paciente</option>
        <option>Mãe do paciente</option>
        <option>responsavel</option>
        <option>Medico Solicitante</option>
    </select> <br>

    <label for='outro'>Outro : </label>
    <input type='' name='outro' id='outro'> <br>

    <a href="" class="ui-button salvar ui-corner-bl ui-corner-tr" style="margin-left: 185px;" data-atalho="CTRL+S" onclick="salvarLaudo()">Salvar</a>

</form>

How to call the Controller ? Through an action of the form? Since I need to use this Controller function:

public function salvarLaudoSolicitacao(){
    $tbLaudoFarmacia = new Application_Model_Farmacia();
}

Then finally arriving at Model :

<?php

    Zend_Loader::loadClass("Elotech_Db_Table_Abstract");
    class Application_Model_Farmacia extends Elotech_Db_Table_Abstract {
        protected $_nome = "tb_laudo_farmacia";
        protected $_primary = "cof_codigo";

        // Método que salva os dados em BD
        public function salvar(array $data) {
                $set_codigo = parent::salvar($data);
        }
    }

?>
    
asked by anonymous 31.08.2018 / 20:21

1 answer

2

You did not leave it explicit, but I see from your code that uses Zend Framework, right?

  

Take a look at the documentation how to set the View layout:

     
    

Zend_Layout Quick Start - Zend_Layout

  

You need to set the correct layout for your view:

$layout->setLayout('foo');

On saving the data with the model, there is a cool article from Diogo Matheus that teaches you how to organize your Models in Zend:

  

Advanced use of models in the zend framework

    
31.08.2018 / 20:27