Custom libraries with custom config files ... how? - 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: Custom libraries with custom config files ... how? (/showthread.php?tid=18964) |
Custom libraries with custom config files ... how? - El Forum - 05-23-2009 [eluser]Aaron Wallentine[/eluser] Hello, The CodeIgniter documentation states thusly: Quote:Passing Parameters When Initializing Your Class Anyone know more specifics on this? I tried this out, making a file in application/config identically named to my library's file name, and added some parameters there; but how are they supposed to be named, and how do you access them from the library? I can't seem to find any documentation on this. Since it doesn't say anything, I assumed that the parameters in the config file would be available as an array passed into the constructor, but that doesn't seem to be the case. I tried naming my parameters in the config file as members of a $config array, as well as an array named after my class. But neither shows up when the class constructor is called. Anyone have anything on this? Thanks Custom libraries with custom config files ... how? - El Forum - 05-24-2009 [eluser]tomcode[/eluser] In Your case the config file needs to be named someclass.php. Inside You have the standard config notation Code: $config['var_key'] = '"Variable Value"'; And in the library Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Custom libraries with custom config files ... how? - El Forum - 05-27-2009 [eluser]Aaron Wallentine[/eluser] Thanks, Tom. That's basically what I did. Here's what I have: file: application/config/AW_forms.php Code: $config['reqd_img_url'] = 'images/reqd_star.gif'; file: application/libraries/AW_forms.php Code: class AW_forms { file: application/config/autoload.php Code: $autoload['libraries'] = array('database', 'AW_forms'); I even tried auto-loading the config file just in case that would make a difference. But in my output I'm consistently getting: Code: hello I am the AW_forms constructor ... Indicating that those params from the config file aren't being passed into the constructor. Does it make a difference that I'm autoloading the library instead of loading it manually? Or perhaps the fact that the second letter of the library/class/config file is capitalized? Or that I'm using __construct() instead of the PHP 4 way of making constructor functions? (I'm using PHP 5 so that shouldn't matter, I'd think) I'll experiment with those things and see if they make a difference. Custom libraries with custom config files ... how? - El Forum - 05-27-2009 [eluser]tomcode[/eluser] Guess You should have the config filename lowercase : aw_forms.php the CI default is : 1. Library : First letter uppercase, rest lowercase 2. config : lowercase If CI works with lcfirst() then your config file needs to be named aW_forms.php (would be very bizzare). autoloading the config file is senseless since CI is passing the data via the constructor, and only the data of the this specific config file. Just to make sure : You have NOT exchanged in config/config.php: Code: $config['subclass_prefix'] = 'MY_'; By the way, you can do also : Code: // a one liner array | object echo EDIT : you might try without autoloading, to be sure |