开发者

How to call different functions in PHP file from iPhone App?

Now I have a app to get some data from php file in web server. and this php file have some some functi开发者_StackOverflowons with get diffierent results with db, and I found that the objective_c can only call the php file and not to call the functions in php, and maybe I am wrong , but how to get the functions of one php file, thank you very much!


Talking about PHP, that's not how it works, function test($arg1, $arg2) is correct, but you need to explicitly call the test function from with ur php

example:

> function test($arg1,$arg2){ //DO some
> stuff }
> 
> $arg1=$_REQUEST['arg1']; //This is
> where u grab the values from the URL
> $arg2=$_REQUEST['arg2'];
> 
> //Then call your function
> 
> test($arg1,$arg2);

So when u called this script with NSString *urlString = [NSString stringWithFormat:@"http:/myphp.php?test&arg1=%@&arg2=%@",@"arg1",@"arg2"]; the php script should work and return whatever is done inside test() function.


You have a couple options. You can send a POST or GET variable in your iPhone HTTP call and use that with a switch on the PHP end to get a function name. That is kind of a pain.

You can use rewriting. HTAccess Info. Which is a bigger pain.

Or you can use a framework that has URI routing built-in. I generally use CodeIgniter. Check out the routing info. This would be my recommendation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜