Welcome Guest, Not a member yet? Register   Sign In
$Variable available in all controllers
#1

[eluser]hugle[/eluser]
Hello Everyone.

I want to call :
Code:
$this->load->helper('date');
$datestring = "%l, %j %F, %G:%i";
$this->data['nav_time'] = mdate($datestring, time());

in every of of controller, so I have $this->data['nav_time'] value in every controller.
I understood that I need to use a hook in pre_controller probably?

But can't understand really how is it done ...
I have looked into howto - but no good resultSad

Anyone can point me on this?
Thank you!
#2

[eluser]davidbehler[/eluser]
You could extend the controller class. Maybe this may work:

Code:
class MY_Controller extends Controller {

    var data;

    function My_Controller()
    {
        parent::Controller();
        $this->load->helper('date');
        $datestring = "%l, %j %F, %G:%i";
        $this->data['nav_time'] = mdate($datestring, time());
    }
}

And in your controllers you now have to extend MY_Controller instead of Controller class and in every one of your controllers the $this->data variable should be available.
#3

[eluser]xwero[/eluser]
why not autoload a custom config file with
Code:
$config['nav_time'] = date('l, j F, G:i');
Or add following to the constants.php file
Code:
define('NAV_TIME', date('l, j F, G:i'));

The mdate function is only useful if you have text inside the dateformat, take a look at the example in the user guide.
#4

[eluser]hugle[/eluser]
Hello again waldmeister and xwero.

I have tried both of your suggestions - both seems to work Smile
Thanks again guys for such a great support !




Theme © iAndrew 2016 - Forum software by © MyBB