Welcome Guest, Not a member yet? Register   Sign In
No Argument Passed to Library Even Though There Should be One
#1

[eluser]kaege[/eluser]
I have this code in my controller:

Code:
$a=array('name'=>'customer');
$this->load->library('ais_form', $a);

And this is how my library look like:

Code:
class Ais_form {
    protected $CodeIgniter;
    private $name;
    private $elements;

    public function __construct($a=array('name'=>'Tri')) {
        $this->name = $a['name'];echo $this->name;

I clearly have supplied library Ais_form with variable $a in the controller. So, $this->name value in the library should be 'customer', but, when I echoed that $this->name, what was displayed was 'Tri' (the initial value). Is there something wrong in my code or is this a bug in CI?
And besides, what was the structure of config file supplying arguments for library? I can't seem to find it in CI user guide or any other CI resource.
#2

[eluser]InsiteFX[/eluser]
Code:
private $name;

public function __construct($a = array())
{
        $this->name = is_array($a) ? $a : array();

        echo $this->name['name'];
}
#3

[eluser]PhilTem[/eluser]
I'm surprised such function headers are possible

Code:
public function __construct($a=array('name'=>'Tri')) {
#4

[eluser]kaege[/eluser]
@PhilTem: It's possible

@InsiteFX: It gave me "undefined index: name"

My library (Ais_form) didn't get the argument even though it should get one.
#5

[eluser]InsiteFX[/eluser]
You must be doing some thing wrong because how do you think CI passes the config arrays to the classes?
#6

[eluser]kaege[/eluser]
[quote author="InsiteFX" date="1342896111"]You must be doing some thing wrong because how do you think CI passes the config arrays to the classes?
[/quote]

I think CI passed the second parameter of $this->load->library() to the constructor of the library which the name was the first parameter for $this->load->library(). Well, basically, I just copy the example from CI user guide (section Creating Libraries). Don't tell me it's wrong :-(
#7

[eluser]Aken[/eluser]
Works fine for me. Has to be something silly in your code. Try starting fresh and seeing where it goes wrong, if at all.




Theme © iAndrew 2016 - Forum software by © MyBB