CodeIgniter Forums
how to make arrays global? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how to make arrays global? (/showthread.php?tid=30031)



how to make arrays global? - El Forum - 04-29-2010

[eluser]ajsie[/eluser]
i wonder how you can make an array global to all controllers?

so that you can have one array and use it for all views like:

$this->load->view('header', $header)

regards

ajsie


how to make arrays global? - El Forum - 04-30-2010

[eluser]eoinmcg[/eluser]
extend the Controller class:
http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html
Replacing Native Libraries with Your Versions

in MY_Controller
Code:
class MY_Controller extends Controller
{

  var $header = array();

  function __construct()
  {
    parent::__construct();

  }

}
then in your controllers, you can reference /. change it with

Code:
$this->header;



how to make arrays global? - El Forum - 04-30-2010

[eluser]ajsie[/eluser]
good solution!