Hi,
I´m trying to use a private var ( $pizzaria ) to store a query result to use in 2 functions of the same class.
My Controller:
class Pizzaria extends CI_Controller {
private $pizzaria;
function __construct()
{
parent::__construct();
$this->pizzaria=array();
init_pizzaria();
$this->load->model('Pizzaria_model');
$this->load->library('session');
$this->load->library('cart');
}
public function mostra_pizzaria(){
$idpizzaria =$this->uri->segment(3);
$this->pizzaria =$this->Pizzaria_model->get_byid('id_pizzaria', $idpizzaria, 'pizzaria')->row();
print_r($this->pizzaria); // this is OK!!!!!
$dados = array( 'tela' => 'mostra_pizzaria2',
'pizzaria' => $this->pizzaria);
set_tema('footerinc', load_js(array('jquery-1.10.2.min','jquery.dataTables','dataTables.foundation','table')),FALSE);
set_tema('titulo','Mostrar Pizzaria');
set_tema('template','pizza_view');
set_tema('conteudo', load_modulo('pizzaria_view',$dados,'pizzaria'));
load_template();
}
/* this function is called after a submit from view mostra_pizzaria2 */
public function cardapio(){
$idx_cardapio=$this->input->post('item_cardapio');
print_r($this->pizzaria); // this is empty!!!!!!
print_r($idx_cardapio);
}
}my View shows a form and submit to cardapio in my controller. So here is the problem, my private var is empty.
case 'mostra_pizzaria2':
echo '<div class="large-6 columns">';
echo '<div class="row"';
echo form_label('Filtrar Cardapio');
echo form_open("pizzaria/cardapio", array('class'=>'custom'));
echo form_dropdown('item_cardapio', $cardapio, $idx_cardapio);
echo form_submit(array('name'=>'filtrar_cardapio','class'=>'button radius tiny'),'Filtrar Cardapio');
echo form_close();
echo '</div>';
echo '</div>';
break;I thought:
1-Controller mostra_pizzaria make the query and assign results to private var $this->pizzaria 2-Controller mostra_pizzaria loads view mostra_pizzaria2 and shows form. 3-View mostra_pizzaria2 return to new controller cardapio and show $this->pizzaria empty. This is my problem.
Is there anything to do to make possible use private var in this case or I need to use a session?
Thanks
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.