Welcome Guest, Not a member yet? Register   Sign In
Passing parameters through an extended library class?
#1

[eluser]Wayne Smallman[/eluser]
Hi guys!

I'm building PDF functionality into an application via FPDF, and all is (almost) working fine.

And to make the FPDF truly useful, I've made it a globally available library. However, I need to pass parameters to the class, which isn't going according to plan.

Code:
function FPDF($orientation='P', $unit='mm', $size='A4') {...
Which I'm extending...
Code:
class Export extends FPDF {
And calling via a controller method...
Code:
$this->load->library('invoices/export', array('orientation' => 'L', 'unit' => 'mm', 'size' => 'A4'));
All of which works in so far as actually calling the library, but not when passing the parameters.

Any ideas how I get that to work?
#2

[eluser]Unknown[/eluser]
Hello
#3

[eluser]Aken[/eluser]
Load your library the same as you have shown, but make sure your extended class controller's construct function includes something to handle a parameters array.
Code:
class Export extends FPDF {

    public function __construct($params)
    {
        parent::__construct($params['orientation'], $params['unit'], $params['size']);
    }

    ...
}
You should also ideally have some additional code to make sure that the $params array will always contain three default values if one or more of them was omitted during the load process.
#4

[eluser]Wayne Smallman[/eluser]
[quote author="Aken" date="1312030195"]Load your library the same as you have shown, but make sure your extended class controller's construct function includes something to handle a parameters array.
Code:
class Export extends FPDF {

    public function __construct($params)
    {
        parent::__construct($params['orientation'], $params['unit'], $params['size']);
    }

    ...
}
You should also ideally have some additional code to make sure that the $params array will always contain three default values if one or more of them was omitted during the load process.[/quote]Aken, thanks for the reply!

I'll give that a try later on today and see how things go.




Theme © iAndrew 2016 - Forum software by © MyBB