|
-
Jul 5th, 2009, 07:50 PM
#1
Thread Starter
Hyperactive Member
Calling a function in a class from an html doc
Is this possible? Don't see why it shouldn't be but thought I would ask before hitting the class bandwagon and stuffing up our development effort 
<form action="process.php?mod=2" method="post">
Using a switch function in process.php to call the correct function.
-
Jul 5th, 2009, 07:53 PM
#2
Re: Calling a function in a class from an html doc
um, if the switch function operates depending on the value of $_GET['mod'], then sure. there's no reason why you couldn't call a different function depending on the value of that variable.
-
Jul 5th, 2009, 07:58 PM
#3
Thread Starter
Hyperactive Member
Re: Calling a function in a class from an html doc
 Originally Posted by kows
um, if the switch function operates depending on the value of $_GET['mod'], then sure. there's no reason why you couldn't call a different function depending on the value of that variable.
kows really wanting to know if I can call a function in a class via the same method. The only example I have is one php script calling another, which is slightly too advance for stage 1 of my super duper software considering the example uses templates and the like. Would rather push that to stage 2 and simply focus on getting the functionality working like a brought one.
-
Jul 5th, 2009, 08:04 PM
#4
Re: Calling a function in a class from an html doc
then, do you mean that you want to have $_GET['mod'] be available within your class? it's a superglobal (meaning it's available in all scopes), so it should work fine.
if this has nothing to do with what you're talking about, then please post an example of the switch function you'd like to be using. I just don't understand what else you could be trying to do from your description.
-
Jul 5th, 2009, 08:09 PM
#5
Thread Starter
Hyperactive Member
Re: Calling a function in a class from an html doc
 Originally Posted by kows
then, do you mean that you want to have $_GET['mod'] be available within your class? it's a superglobal (meaning it's available in all scopes), so it should work fine.
if this has nothing to do with what you're talking about, then please post an example of the switch function you'd like to be using. I just don't understand what else you could be trying to do from your description.
The switch function works fine and dandy, however currently we have to repeat code, db connections etc, in each function and am trying to get around that by wrapping everything in a class and using declares at the top. Was wondering if I called a function from a html document would it matter if the function was part of a class?
Hope that makes more sense.
-
Jul 5th, 2009, 08:21 PM
#6
Re: Calling a function in a class from an html doc
it wouldn't matter if the class file was included in the "html" file (I hope you mean PHP by this!).
you should never need to repeat database connections, though. I'm not sure if the connection -is- global, but even if it isn't, you could make the database connection (which would be declared publicly) available to your functions by using the "global" method.
PHP Code:
function test($sql){
global $myconnection;
mysql_query($sql, $myconnection);
}
or, you could probably even pass the connection to the function. either way! :)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|