Global Variable - codeigniter

0

Hello

I want to display a data ($ variable) in a footer.

As it is below, it works and the $operador variable is displayed correctly on all the options / screens I click.

<?php $operador = $this->session->userdata('nome'); ?>

<div id="footer" class="span12"> <?php echo date('Y'); ?> | Versão: <?php echo $operador; ?>

But I do not want to display a $variável of the session.

Then I created a controller / modal / view called SYSTEM .

In this controller I have idSistema, nome, data_registro, date_expiracao, licenca, versao .

So I want to display the version in the footer.

So I tried the following way:

<div id="footer" class="span12"> <?php echo date('Y'); ?> | Versão: <?php foreach ($results as $r) { echo $r->versao; }?></div>

But this only works if I am in the SYSTEM option, if I click on another option, where it should show the system version, the message that the results variable is not defined is displayed.

How can I set this variable as global ??

Below, part of the function code in the system controller.

$this->data['results'] = $this->sistemas_model->get('sistemas','idSistemas,nome, dt_registro,dt_expiracao,licenca,versao','',$config['per_page'],$this->uri->segment(3));
$this->data['view'] = 'sistemas/sistemas'; $this->load->view('tema/topo',$this->data);

    
asked by anonymous 28.10.2016 / 21:03

1 answer

5

You can use codeigniter% s native function %

You basically need to define which variables you want to make global using

$this->load->vars();

Place this function in the "base" class of codeigniter vars() as in the example below;

class CI_Controller {

    public function __construct()
    {
        ...
        $this->load->vars(['name' => 'variabel global']);
        // Dentro da função vars você pode chamar 
        // uma outra função que retorna um array com os dados do sistema
    }

Now just use the variable in the view CI_Controller .

    
28.10.2016 / 22:42