Solved

how to point the paremeter variable from config to class

Posted on 2008-06-19
18
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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 i…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

729 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