CakePHP 和 PHP更改用户的个人资料

发布于 2024-12-12 05:29:29 字数 649 浏览 0 评论 0原文

我已经开始学习cakePHP,现在面临以下问题。如何允许我的用户更改他们的个人资料(他们在数据库中的信息)。

这是我的模型 -> http://bin.cakephp.org/view/798927304 当有人尝试时,我会使用这些验证登记 。 这是我编辑配置文件的方法: http://bin.cakephp.org/view/841227800

首先,我检查用户是否有权编辑此配置文件(该配置文件是他自己的)。 然后获取所需的id并尝试保存请求->数据...但不幸的是没有成功。

最后这是我的观点 -> http://bin.cakephp.org/view/1798312426

我唯一想做的是: -更改他们的电子邮件(如果他们添加新电子邮件) -更改他们的社交资料(如果添加他们) -更改他们的密码(如果他们添加了密码)

你能指导我做这些事情吗?

提前致谢!

I have started learning cakePHP and now I am facing the following problem. How can allow my users to change their profile (their info in the DB).

This is my model -> http://bin.cakephp.org/view/798927304 I use these validations when someone tries to register .
This is my method for editing profiles: http://bin.cakephp.org/view/841227800

First I check does the user have the permission to edit this profile (is the profile his own).
Then get the desired id and try to save the request->data... But unfortunately without success.

And last this is my view -> http://bin.cakephp.org/view/1798312426

The only things I want to make are:
-Change their email (if they add new email)
-Change their social profiles (if the add them)
-Change their password (if they add it)

Can you guide me to do these things?

Thanks in advance!

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

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

发布评论

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

评论(2

爺獨霸怡葒院 2024-12-19 05:29:29

通常,当您调用保存时,如下所示:

$this->User->save($this->request->data)

$this->request->data 中的数据默认被清除。在您的编辑方法中,下面有一个 if 语句,它再次使用相同的保存。

我假设您从 cakebaked 编辑方法复制的默认功能通常会进行保存并使用返回的逻辑来支持 if 语句。第二次调用它时,您可能会返回 false,这可能会跳过该 if 语句。

为了调试这个,我建议在不同的位置中使用其中的几个:

debug($this->request->data);

此外,调试打印输出在重定向时被清除,因此同时,您可能需要注释掉 if 语句内的重定向,如下所示:

if ($this->User->save($this->request->data)) {
    $this->Session->setFlash('Успешно променихте профила си.', 'success_message');
    //$this->redirect(array('action' => 'profile'));
}

Typically, when you call a save, as in:

$this->User->save($this->request->data)

The data in $this->request->data is cleared by default. In your edit method, you have an if statement below that is using the same save again.

The default functionality which I assume you have copied from a cakebaked edit method typically does the save and uses the returned logic to power that if statement. The second time you call it, you might be getting a false returned, which is likely skipping over that if statement.

To debug this, I suggest several of these in different locations:

debug($this->request->data);

Also, debug printouts are cleared on redirect, so in the mean time, you may want to comment out the redirect inside the if statement like so:

if ($this->User->save($this->request->data)) {
    $this->Session->setFlash('Успешно променихте профила си.', 'success_message');
    //$this->redirect(array('action' => 'profile'));
}
温柔一刀 2024-12-19 05:29:29
if($this->Auth->user() && $this->Auth->user('id') == $id) {
    $this->User->read(null, $id);
    $this->User->set(array(
        'email' => $this->data['User']['email'],
        'password' => $this->data['User']['password'],
        'social_profile' => 'bla bla'
    ));
    $this->User->save();
    // etc

可能会做你想做的事。

更多 @ http://book.cakephp.org/view/1031/Saving-Your -数据

if($this->Auth->user() && $this->Auth->user('id') == $id) {
    $this->User->read(null, $id);
    $this->User->set(array(
        'email' => $this->data['User']['email'],
        'password' => $this->data['User']['password'],
        'social_profile' => 'bla bla'
    ));
    $this->User->save();
    // etc

may do what you're after.

more @ http://book.cakephp.org/view/1031/Saving-Your-Data

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