0

I´m aware that with

loader = new URLLoader();
loader.data;

it´s possible to get the entire data/information from a php page.. But I don't want a php page for every bit of information I want from to 'stream'.

So my Question is: Is it possible to have multiple functions/methods in a php script, and only call the method I require?

such as:

<?php
   function getColour1()
      echo "blue";

   function getColour2()
      echo "red";
?>

If "yes", 2 lines of code that show how, or link to an example would be greatly appreciated.

cheers, M

5 Answers 5

2

You can pass an "action" variable to PHP, then use if/else statements in PHP tp respond to that action.

Sign up to request clarification or add additional context in comments.

Comments

2

Check out the AMFPHP project: http://www.silexlabs.org/amfphp/

It does what you're looking for

1 Comment

whoa. I don't doubt it works.. but i'm only starting off with Php and just want to push a few variables around.
1

You could call the page like this:

http://www.site.com/script.php?action=getColour1

Then in your code:

<?php

switch($_GET["action"]) {

    case "getColour1":
        getColour1();
        break;
    case "getColour2":
        getColour2();
        break;
    default:
        echo "Unknown action";
        break;
}

?>

Comments

1

You want to hear about Front Controller Pattern.

Moreover, you need to route your request to different functions - I advise you to use this beautiful library, if you don't want to go with a full framework MVC stack.

Comments

0
$functionName = $_GET["action"];
$functionName() or call_user_func($functionName)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.