duanlan6259
duanlan6259
2013-12-09 12:29
浏览 58

将现有PHP文件和函数包含在Slim结果中,传回空变量

I am beginning to use Slim for REST/Json web services. Now, after initial tests, I realize that I would need to include PHP code which I use for my "normal" web application, in order to calculate the right values to be returned. [That is, instead of returning national statistics, I calculate per capita data or indexed values or aggregations.]

Now, my PHP code in the included file (see below, B) calls a function from another file (C). This works fine. But the value generated in that function is not being brought back to the first file (B).

  • A: Code Slim level.... include (xx.php, yy.php)
  • B: xx.php: call_to_function_from_yy()
  • C: yy.php: generate result; global $results (with $results having indeed values)
  • B: $results is empty

Any hints why that would be and what I can do? Thanks a lot!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsbckxk165039
    dsbckxk165039 2013-12-09 12:44

    Assuming your yy.php has something like this:

    function returnResults($parameter) {
     /*
      * your pretty code here
      */
     return $results;
    }
    

    And your xx.php file does something like this:

    require_once $path_to_your_file . '/yy.php';
     /*
      * your pretty code here
      */
    
    $myResults = returnResults($myParameter);
    
     /*
      * your pretty code here
      */
    

    In this way you get the result from yy.php in xx.php, I can improve this answer if you could who a lil' snippet of yy.php and xx.php.

    点赞 评论

相关推荐