Welcome Guest, Not a member yet? Register   Sign In
reuse varibale in model
#1

[eluser]Russell Keith[/eluser]
I have the follwing variable declared in every function in my model:

$client = new soapclient("http://localhost:9090/summit/3440-TRAIN/services/CmdSpectrum?wsdl");

I would like to only declare it in one place and reuse it but I can't seem to find the correct location. Any help would be great.
#2

[eluser]jedd[/eluser]
[quote author="Russell Keith" date="1256934083"]
I have the follwing variable declared in every function in my model:

$client = new soapclient("http://localhost:9090/summit/3440-TRAIN/services/CmdSpectrum?wsdl");

I would like to only declare it in one place and reuse it but I can't seem to find the correct location. Any help would be great.
[/quote]

If you truly have just the one model, declare it in your constructor.

If you have multiple models and you want it in all of them, extend the core model - using the MY_Model thing in /application/libraries/ - see the manual for 'extending core libraries'.
#3

[eluser]Russell Keith[/eluser]
I have tried:
Code:
function MPw()
    {
        parent::Model();
        $client = new soapclient("http://localhost:9090/summit/3440-TRAIN/services/CmdSpectrum?wsdl");
    }

but the variable is not available in the subsequent functions.
#4

[eluser]jedd[/eluser]
Code:
$this->client = new soapclient("http://localhost:9090/summit/3440-TRAIN/services/CmdSpectrum?wsdl");
#5

[eluser]Russell Keith[/eluser]
That is amazing. This should be included in the User Guide. Thank you very much!!
#6

[eluser]Colin Williams[/eluser]
It is amazing. And it's just vanilla PHP. It's not the user guide's job to document PHP.




Theme © iAndrew 2016 - Forum software by © MyBB