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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献