Jump to content

How to pass a variable from a function to another?


lopes_andre

Recommended Posts

Hi,

 

I have one problem... I need to pass a variable from a function to another, but I don't know if it is possible.

 

The situation...

 

The controller:

class Ads extends Controller {
    
    public $contratofinal;
    
    function Ads() {
        parent::Controller();
        
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->helper('array');

    }

    function ads_p4() {
        $this->load->model('Template_model');
        $this->load->model('Ads_model');
        

        $function_name = 'ads_p4';
        $title = 'Some Title';
        $resultTemp = $this->Template_model->getZonasComAnunciosActivos();
        
        $replaces_anuncio = $this->Ads_model->getDadosAnuncio($this->session->userdata('id_anuncio_externo'));
        
        $timestamp = date("Y-m-d H:i:s");
        

        $replace = array(
        '@nome_real@' => $replaces_anuncio->n_anunciante,
        '@nacionalidade@' => $replaces_anuncio->n_nacionalidade,
        '@data_nascimento@' => $replaces_anuncio->dat_nasc,
        '@endereco_ip@' => $this->input->ip_address(),
        '@hora_assinatura@' => $timestamp
        );
        
        $contratobruto = $this->Ads_model->getDocumento('concord_anun_gratui');
        
        $contratofinal = replaceemarray($replace, $contratobruto->documento);
        
        $this->data_view['documento'] = $contratofinal;
        
        $this->data_template['function_name'] = $function_name;
        $this->data_template['title'] = $title;
        $this->data_template['resultTemp'] = $resultTemp;
                        
    
        $this->load->view ('common/template_view', $this->data_template);
    
    }


function submeter_contrato() {
        $this->load->model('Anunciosgratuitos_model');
        
        if ($this->input->post('aceito')) { $this->Ads_model->setInsAnunciosDeclaracoes(
$this->session->userdata('id_anuncio_externo'), 
$contratofinal, 
$this->input->ip_address(), 
date("Y-m-d H:i:s"));

        } else if ($this->input->post('n_aceito')) {
            // To do
        }
        
    }

}

 

Ok... The global view of the problem is this... I have one page/function "ads_p4" that generates the contract, the variable $contratofinal have HTML code. The function "submeter_contrato" handles a form submission.

 

What I need is to pass the value of the variable $contratofinal from the function "ads_p4" to the function "submeter_contrato". How can I do that? The variable $contratofinal contains HTML code.

 

Sorry for my bad english.

 

Best Regards,

Just call the function inside the first.  Put the variables you want to pass between the two methods inside the class declaration. 

 

class Ads extends Controller {
    
    public $contratofinal;
    private $variables_to_pass_between_functions
    

 

 

function submeter_contrato() {
$this->ads_p4();
}

 

 

From inside your submeter_contracto() and ads_p4 function you may access this variable by referencing

$this->$variables_to_pass_between_functions

 

of course you aren't limited to using one variable here, so you can pass objects of varying types between your methods inside your class.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.