How to save data through Model?

Asked

Viewed 41 times

0

My difficulty with MVC 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 a action form? Since I need to use this form function Controller:

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

So finally arriving at the 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);
        }
    }

?>

1 answer

2

You didn’t 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 of your view:

$layout->setLayout('foo');

About saving data with the model, there’s a nice article by Diogo Matheus that teaches you how to organize your models in Zend:

Advanced use of models in zend framework

  • As it is my first work in the areá I am well lost in general but I appreciate the indications of readings

  • It’s normal at first. What tools and Frameworks are you using? When you have 50 reputation points you can access our chat: Stack Burst

  • Here we work with PHP, html, JS, Ajax, Json, ZEND 1 if I’m not mistaken (project older than 10 years ) and postgres

  • Cool. I worked on several projects made in Zend. When you can and want to exchange an idea call me there in chat.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.