CakePHP:如何构建用户个人资料页面

发布于 2024-10-16 07:14:49 字数 845 浏览 11 评论 0原文

我们如何构建一个输出用户数据的个人资料页面?并且此页面只能由登录的用户查看。这就像我们进入个人资料页面并查看自己的用户名、密码、电子邮件、地址等一样。然后我们就可以自己编辑了。当然,其他用户不能对其进行编辑。

我对配置文件表的需要感到困惑,现在我认为我们不需要它?我们可以在我们创建的 profile.ctp 页面上使用一些 PHP 逻辑来填充数据吗?

这很令人困惑,我遵循了这个 http://book.cakephp.org/#!/ view/1041/hasOne 并创建了一个配置文件表,其中包含用户表的一些字段,然后使用名为 user_id 的外键。我检查了用户和配置文件模型都在关系中正确定义。我在配置文件模型中有这个:

var $belongsTo = array(
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )

在用户模型中有这个:

var $hasOne = 'Profile'; 

当我浏览到我的个人资料/索引时,有一些字段名称没有任何记录。这是空集。我认为它应该从用户表中检索数据?

为现有用户和即将进行的注册创建个人资料页面的最佳方式是什么?

How do we build a profile page that outputs the user's data? and this page can only be viewed by the user who logged in. It's something like when we go to our profile page and view our own username, password, email, address..etc. Then we may edit it by ourselves. It, of course can't be edited by other users.

I'm confused with the need of a profile table, now I think we would not need it? we can just populate the data using some PHP logic on a page we create as profile.ctp ?

This is confusing, I followed this http://book.cakephp.org/#!/view/1041/hasOne and created a profile table with some fields my users table has, and then with a foreign key called user_id. I checked on User and Profile model both are correctly defined in the relationship. I have this in Profile model:

var $belongsTo = array(
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )

and this in User model:

var $hasOne = 'Profile'; 

As I browse to my profile/index there are field names without any records. It's empty set. I thought it was supposed to retrieve data from the users' table ??

What's the best way to create a profile page for the existing users.. and the upcoming registrations ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗恋未遂 2024-10-23 07:14:49

您不需要配置文件表(如果您已经有一个包含其信息的用户表)。

完成此操作的一种方法是,在用户验证后,将他的 ID 与他想要可视化的个人资料的用户 ID 进行比较。如果这些匹配,则该用户正在查看自己的个人资料,您可以让他查看自己的信息。

当然,如果您考虑将其设为公共可访问的网站,则必须考虑大量的安全问题。

You do not need a profile table (if you already have a users table with their info).

One way of having this done is, after user validation, compare his id with id of the user which profile he wants to visualize. If those match, then it's a user who is viewing his own profile, and you can let him view his info.

Ofcourse there's a great deal of security issues you would have to take into account if you are thinking to make this a public accessible web site.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文