lopes_andre Posted March 28, 2010 Share Posted March 28, 2010 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, Link to comment https://forums.phpfreaks.com/topic/196824-how-to-pass-a-variable-from-a-function-to-another/ Share on other sites More sharing options...
andrewgauger Posted March 28, 2010 Share Posted March 28, 2010 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. Link to comment https://forums.phpfreaks.com/topic/196824-how-to-pass-a-variable-from-a-function-to-another/#findComment-1033264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.