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

将现有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 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.

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题