Solved

how to point the paremeter variable from config to class

Posted on 2008-06-19
18
220 Views
Last Modified: 2008-06-20
PHP

How can i point the parameter variable in my config file to a class

i have a class call TEST class
i also have a main.php where i use to create object of class
i have also config.php --> use to ease end user to change the setting

now in my config file i have this


**config.php***
$localFolder = "c:/TEST";    
$host = "hostname";        
$user = "username";            
$pass = "password";  
$remoteFolder = '/JOHN/TEST';  
$this->uploadFiles($localFolder, $host, $user, $pass, $remoteFolder);

in my class i have this

***TEST.php***
class Test
{
....
function uploadFiles($localFolder, $host, $user, $pass, $remoteFolder)
{}
....
}

in my main i have

****main.php***
include "Test.php";
$a = new Test();
$a->otherfunction();

Since i had create object Test class i cannot create the same object class in config file
that mean i cannot do this

****config.php***
include "Test.php";
$b = new Test();
$b->uploadFiles($localFolder, $host, $user, $pass, $remoteFolder);

if i cannot use the method above i cannot pass the parameter to the class.

another method i use is using $this->
but using $this-> it keep looping without end.

what is the proper way to do this




0
Comment
Question by:firekiller15
  • 9
  • 9
18 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 21820407
Hi,

You pass parameters at the exact moment when you call the function.

You could just use

$a = new Test();
$a->uploadFiles('c:/test1', 'server', 'user', 'password', '/www/test1');
$a->uploadFiles('c:/test2', 'server', 'user', 'password', '/www/test2');
$a->uploadFiles('c:/test3', 'server', 'user', 'password', '/www/test3');
0
 

Author Comment

by:firekiller15
ID: 21827932
if i put this in
$a = new Test();
$a->uploadFiles('c:/test1', 'server', 'user', 'password', '/www/test1');
how can i point the value from config to main?

i cannot put the value in the parameter because it does not ease end user to change the setting in the future
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21828568
In config you would have your properties:
$host = 'something';
$user = 'something';
$password = 'something';
$localFolder1 = 'something';
$remoteFolder1 = 'something';
$localFolder2 = 'something';
$remoteFolder2 = 'something';

then have

$a = new Test();
$a->uploadFiles($localFolder1, $host, $user, $password, $remoteFolder1);
$a->uploadFiles($localFolder2, $host, $user, $password, $remoteFolder2);
0
 

Author Comment

by:firekiller15
ID: 21828668
i dont think can do like this
i had try to do as follow
i call by include("config.php"); in main
i received this error message
Fatal error: Using $this when not in object context in C:\wamp\www\test\config.php on line 49
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21828684
That is correct. You are not in a object in the config, as it is a config and not execution.

Remote the $this->uploadFiles($localFolder, $host, $user, $pass, $remoteFolder); line and use the $a = new Test() stuff from later.
0
 

Author Comment

by:firekiller15
ID: 21828757
you mean i place this Remote the $this->uploadFiles($localFolder, $host, $user, $pass, $remoteFolder); in config file?

i try this also..
i can get the result but
i get the result again and again its like never ending
looks like im looping and looping the data.
also in my config file i have other value.
but if i use $this-> other data cannot be execute by other function
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21828777
No.

Config file holds config only!
[config.php]
$host = 'something';
$user = 'something';
$password = 'something';
$localFolder1 = 'something';
$remoteFolder1 = 'something';
$localFolder2 = 'something';
$remoteFolder2 = 'something';

Your main file holds the calls to the upload functions:

[main.php]
$a = new Test();
$a->uploadFiles($localFolder1, $host, $user, $password, $remoteFolder1);
$a->uploadFiles($localFolder2, $host, $user, $password, $remoteFolder2);

0
 

Author Comment

by:firekiller15
ID: 21828865
so you mean
Config file holds config only!
[config.php]
$host = 'something';
$user = 'something';
$password = 'something';
$localFolder1 = 'something';
$remoteFolder1 = 'something';
$localFolder2 = 'something';
$remoteFolder2 = 'something';

[main.php]
include("config.php");
$a = new Test();
 $this->uploadFiles($localFolder, $host, $user, $pass, $remoteFolder);

??
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21828876
Yeah, otherwise I wouldn't have typed it.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:firekiller15
ID: 21828973
you type
$a->uploadFiles($localFolder2, $host, $user, $password, $remoteFolder2);

is $a or $this??
0
 

Author Comment

by:firekiller15
ID: 21828975
if u mean $this cannot received

Fatal error: Using $this when not in object context in C:\wamp\www\ERI\config.php on line 49

if u mean $a i already post above why cannot use $a
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21828987
You can use $this only INSIDE an object. As you have not an object yet, you need to instantiate one. That is why you NEED to use $a.
I don't understand why you think $a cannot be used. Configurability is not an issue when using $a as I explained.
0
 

Author Comment

by:firekiller15
ID: 21828994
furthermore if u want to put $a->uploadFiles($localFolder2, $host, $user, $password, $remoteFolder2);
this in main.php is imposible

because you need to call the value from config.php and that mean you need to include config.php in main
. this will cause an errror of this
Fatal error: Using $this when not in object context in C:\wamp\www\test\config.php on line 49
0
 

Author Comment

by:firekiller15
ID: 21828996
do you mind to show the detail of the code how to do this ?
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21829000
I posted it already:

[config.php]
$host = 'something';
$user = 'something';
$password = 'something';
$localFolder1 = 'something';
$remoteFolder1 = 'something';
$localFolder2 = 'something';
$remoteFolder2 = 'something';

Your main file holds the calls to the upload functions:

[main.php]
$a = new Test();
$a->uploadFiles($localFolder1, $host, $user, $password, $remoteFolder1);
$a->uploadFiles($localFolder2, $host, $user, $password, $remoteFolder2);

Can you explain why this does not work for you?
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21829006
For main.php you would indeed have to do some includes:


[main.php]
<?php
include 'config.php';
include 'Test.php';

$a = new Test();
$a->uploadFiles($localFolder1, $host, $user, $password, $remoteFolder1);
$a->uploadFiles($localFolder2, $host, $user, $password, $remoteFolder2);
0
 

Author Comment

by:firekiller15
ID: 21829113
cannot i do as what you state above i received this error message
Fatal error: Using $this when not in object context in C:\wamp\www\sample\config.php on line 49

just that instead of this two
$a->uploadFiles($localFolder1, $host, $user, $password, $remoteFolder1);
$a->uploadFiles($localFolder2, $host, $user, $password, $remoteFolder2);

i use only
$a->uploadFiles($localFolder1, $host, $user, $password, $remoteFolder1);
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 250 total points
ID: 21829144
You would remove the $this->uploadFiles from the config file line 49, as you use $a instead.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now