douju6850 2014-05-28 06:45
浏览 79
已采纳

传递.php文件作为参数

Perhaps I'm going about this the wrong way, but I have a Configuration file that I'm trying to pass through a parameter, the reason I'm doing this is because I'm experimenting with what I call a ("Core"/"Client") structure, probably not the correct name, but basically whatever I edit on the "Core" is updated to all of the "Client" subdomains, which will respectively call code such as

include '/path/to/core/index.php';
generateIndex($Param, $Param);

So, Basically, here's what I have, on the "Clients" side I have a Configuration file, called "Configuration.php" this holds all of the static variables pertaining to the Clients database. Example below:

<?php
    $SQL_HOST = "";
    $SQL_DATBASE = "";
    $SQL_ACCOUNT_TABLE = "";
    $SQL_DATA_TABLE = "";
    $SQL_REWARDS_TABLE = ""; 
    $SQL_USERNAME = "";
    $SQL_PASSWORD = "";
?>

So, Basically, I'm trying to do this,

generateIndex($SQLConnection, $Configuration);

However, It's not allowing me to do so and presenting me with this error.

Notice: Undefined variable: Configuration in /opt/lampp/htdocs/client/index.php on line 16

Respectively, Line 16 is the line above containing "generateIndex"

Now, on the "Core" side what I'm trying to do is the following to get data.

function generateIndex($SQLConnection, $SQLConfig) {
    ...
        $SQLConfig->TBL_NAME
    ...
}

Which I don't know if it throws an error yet, because I can't pass $Configuation to the function.

  • 写回答

3条回答 默认 最新

  • dongxiaoyan4388 2014-05-28 06:48
    关注

    Your can user return context for get variable from file.

    As example:

    File db_config.php:

    <?php 
    return array(
      'NAME' => 'foo_bar',
      'USER' => 'qwerty',
      'PASS' => '12345',
      // Any parameters
    );
    

    You another file with include configuration:

    <?php
    // Code here...
    $dbConfig = include 'db_config';
    // Code here
    

    If file have a return statement, then your can get this values with = operator and include file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站