CodeIgniter Forums
How to initialize the constructor within the PEAR library - 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 initialize the constructor within the PEAR library (/showthread.php?tid=15891)



How to initialize the constructor within the PEAR library - El Forum - 02-17-2009

[eluser]webbymonk[/eluser]
Hi guys, how are you guys?

I just tried the pear integration within CI. And i found some difficulties to initialize th e parameter within the constructor.

If we load the CI library, we have $params to pass through the library.
for ex: $this->load->library('library',$params);

as in the http://codeigniter.com/wiki/PEAR_integration/

in the example;
$http_request = $this->pearloader->load('HTTP','Request');

how initialize the class constructor that contains some parameter?

usually we do in the PHP
Code:
$serializer = new XML_Serializer(array(
                'rootName' => $this->_rootName,
                'indent' => "\t",
                'mode' => 'simplexml',
                'prependAttributes' => '_',
                'parseAttributes' => true
            ));

Thanks...


How to initialize the constructor within the PEAR library - El Forum - 02-18-2009

[eluser]pistolPete[/eluser]
[quote author="webbymonk" date="1234955741"]
how initialize the class constructor that contains some parameter?
[/quote]
The second paramater is used to pass parameters to the constructor, but it has to be an array (as of CI 1.7):
Code:
$this->load->library('library_name',array('key2'=>'value1', 'key2'=>'value2');
Just have a look at the user guide: http://ellislab.com/codeigniter/user-guide/libraries/loader.html

Quote:usually we do in the PHP...
Since CI is PHP, you can do the exact same thing.
Use require and new if you don't want to use the Loader Class.


How to initialize the constructor within the PEAR library - El Forum - 02-18-2009

[eluser]webbymonk[/eluser]
Thanks for your kindly response. I figured it out actually there is a third parameter also in the PEAR Integration library. I just found it, and also has to be array...