• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pass a variable to an autoloaded library.

#1
[eluser]DephNet[Paul][/eluser]
Hi Guys,

I have written a library that generates my page headers and footers, and have set it up to be auto loaded, but I am having a bit of trouble passing a variable to the library, the main one will be for my page title.

I have read the user guide, that only deals with a library loaded from the controller, but am stuck with this, how do you pass a variable, from a controller, to an auto loaded library?

Many thanks for your help
--Paul

#2
[eluser]ramm[/eluser]
Maybe with the $config array?

Can i ask why would you want to generate static data with a library instead of using a template for that?

#3
[eluser]DephNet[Paul][/eluser]
[quote author="ramm" date="1299224913"]Maybe with the $config array?[/quote]How would you go about referencing the config array in the library? Every time I have tried to do this I get an error about $config not being set.

[quote author="ramm" date="1299224913"]Can i ask why would you want to generate static data with a library instead of using a template for that?[/quote]Because there is alot of stuff that goes on in creating my headers, and a library is, from where I am sat, the best place for this to go.

--Paul

#4
[eluser]ramm[/eluser]
Well, i was thinking the same way it works for other libraries, let's say
Code:
//For a googlemaps lib i'm using
$this->load->library('googlemaps');
$config['center'] = 37.4419, -122.1419;
$config['zoom'] = 16;

$this->googlemaps->initialize($config);

//You can do the same here
$config['page_title'] = "Your title";

As in the library itself they have it like this:
Code:
class Googlemaps {
  var $center = "37.4419, -122.1419";
  var $zoom   = 13;
  //some others

  function Googlemaps($config = array())
  {
    if (count($config) > 0)
    {
       $this->initialize($config);
    }    
  }


  function initialize($config = array())
  {
    foreach ($config as $key => $val)
    {
      if (isset($this->$key))
      {
        $this->$key = $val;
      }
    }
  }

}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.