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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退