【问题标题】:How to update the user table with Ion Auth update如何使用 Ion Auth update 更新用户表
【发布时间】:2016-02-18 19:04:11
【问题描述】:

我正在尝试在我的应用程序上实现更改电子邮件和更改密码功能,在研究了有关堆栈溢出的文档和问题后,我似乎仍然遇到了麻烦。

我有一个视图可以传递要使用的新电子邮件,如下所示:

<?php echo form_open("change_email"); ?>
  <input name="changeemail" type="text" class="form-control" placeholder="New Email">
  <button type="submit" class="submit AccountButton">Submit</button>
<?php echo form_close(); ?>

我的控制器应该将这些数据与所需的 id 和多维数组一起传递给更新函数,如下所示:

public function change_email()
{
$userId = $this->ion_auth->get_user_id();
$newemail = $this->input->post('changeemail');
$data = array(
    'email' => $newemail,
);
$this->ion_auth->update($userId, $data);
}

执行此函数后没有收到任何错误,在检查数据库时似乎没有任何变化。

有人可以提供一些帮助吗?

【问题讨论】:

  • 没有db->where.
  • $this-&gt;ion_auth-&gt;update($userId, $data); 正在返回 TRUE?
  • 我发现了问题 - 代码正确执行并返回 TRUE。但是,由于某种原因,在单击提交按钮后,我并没有被定向到 /change_email 以使代码实际执行。知道为什么会这样吗?
  • 使用form_open中控制器的名称即&lt;?php echo form_open("controller/change_email"); ?&gt;
  • 是的,我在应用程序中更正了这一点,但无济于事——我仍然没有被重定向

标签: php codeigniter ion-auth


【解决方案1】:

尝试使用 db where

public function change_email()

{
$userId = $this->ion_auth->get_user_id();
$newemail = $this->input->post('changeemail');
$data = array(
    'email' => $newemail,
);
$this->db->where('some_user_id_name', $userId);
$this->db->update('user_table_name', $data);
}

【讨论】:

  • 函数ion_auth-&gt;update($userId, $data);在内部处理。
【解决方案2】:

我不记得在 Ion_Auth 库中看到 get_user_id() 方法。你可以这样做:

$user = $this->ion_auth->user()->row();
$userId = $user->id;
$newemail = $this->input->post('changeemail');
$data = array(
    'email' => $newemail,
);
$this->ion_auth->update($userId, $data);

希望这对您有所帮助。

【讨论】:

    猜你喜欢
    • 2011-12-31
    • 2016-01-23
    • 2018-12-14
    • 2016-07-16
    • 2014-08-07
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多