简体   繁体   English

在外部PHP文件上调用Cake PHP UserID

[英]Calling Cake PHP UserID on outside PHP file

Actually am trying to get user id from cakephp, php file was placed outside folder. 实际上我试图从cakephp获取用户ID,php文件放在文件夹外。 How can I get user ID from 'users' table. 如何从“用户”表中获取用户ID。

function get_user_id() 
{
    $userid = NULL;

    if (!empty($_SESSION['userid']))
    {
        $userid = $_SESSION['userid'];
    }

    return $userid;
}

There is no such thing as "cakephp" database. 没有“cakephp”数据库​​这样的东西。

What you probably mean is that a SQL database is being used by a CakePHP application. 你可能意味着CakePHP应用程序正在使用SQL数据库。

Cake provides config files where database details are indicated, and Cake engine will use these details to interact with the database (create new users, update user's data, etc). Cake提供指定数据库详细信息的配置文件,Cake引擎将使用这些详细信息与数据库交互(创建新用户,更新用户数据等)。

Then if you want to access the same database with an external PHP script that doesn't know about the config files that CakePHP uses you need to use the methods that PHP have to access the database and throw a SQL query against it (SELECT...) 然后,如果要使用外部PHP脚本访问同一数据库,而该外部PHP脚本不了解CakePHP使用的配置文件,则需要使用PHP必须访问数据库的方法并针对它抛出SQL查询(SELECT .. 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM