在datatable编辑器中访问会话变量

时间:2017-06-30 05:53:57

标签: php datatables jquery-datatables-editor

我想在应用程序生命周期中动态设置数据库凭据。由于我无法从调用我的编辑器自动加载器的类函数中执行此操作,因此我选择将数据表编辑器的.config文件编辑为此

with list as(
    select * from dbo.split(@Param,' ')
)
SELECT aidi, bariu FROM teeburu
    INNER JOIN list
    ON bariu like '%'+ list.items+ '%'
    GROUP BY aidi, bariu

然而,按照我的日志,我似乎无法访问会话变量

require_once('../functions/functions.php'); //get db credentials $db_credentials = get_db_credentials($_SESSION['MY_DATA']['tenant_uuid']); $sql_details = array( "type" => "Mysql", "user" => $db_credentials['datastore_db_username'], "pass" => $db_credentials['datastore_db_password'], "db" => $db_credentials['datastore_db_name'], "host" => $db_credentials['datastore_db_host'], "dsn" => "", "port" => "", );

我错过了什么?

1 个答案:

答案 0 :(得分:0)

我终于找到了解决方法。我需要做的就是在函数文件中包含 DataTables \ Database 命名空间,然后继续创建一个新的数据库实例。更改函数中的全局变量非常棘手。

编辑config.php文件时无需麻烦。

最终解决方案:

   use
       DataTables\Database,
       DataTables\Editor,
       DataTables\Editor\Field,
       DataTables\Editor\Format,
       DataTables\Editor\Mjoin,
       DataTables\Editor\Options,
       DataTables\Editor\Upload,
       DataTables\Editor\Validate;

在功能

$db_credentials = get_db_credentials($_SESSION['MY_DATA']['tenant_uuid']);

$sql_details = array(
    "type" => "Mysql",
    "user" => $db_credentials['datastore_db_username'],
    "pass" => $db_credentials['datastore_db_password'],
    "db"   => $db_credentials['datastore_db_name'],
    "host" => $db_credentials['datastore_db_host'],
    "dsn"  => "", 
    "port" => "",
);

$db_details = new Database( $sql_details );