Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to point the paremeter variable from config to class

Posted on 2008-06-19
18
Medium Priority
?
236 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
Independent Software Vendors: 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 1000 total points
ID: 21829144
You would remove the $this->uploadFiles from the config file line 49, as you use $a instead.
0

Featured Post

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!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

596 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