dongxiong1941 2014-12-22 12:37
浏览 23
已采纳

如何允许用户编辑自己的帐户详细信息?

how would i allow a user to edit their own account details. When they login, a session is created with their username. How do i query the database where i match the session to a user in the database? Im confused as to where to do it, controller, or model? Here is my code. Its not much because i really don't know where to start with this:

Controller:

public function myaccount()
 {
     if($this->session->userdata('logged_in'))
{

$session_data = $this->session->userdata('logged_in');
$data['id'] = $session_data['id'];
$this->myaccount_model->get_details($data);
$this->load->model('myaccount_model');
$this->load->view('head');
$this->load->view('myaccount', $data);
$this->load->view('footer');

}
else
{
 redirect('login', 'refresh');
}
 }

Model:

<?php
class Myaccount_model extends CI_Model {

public function __construct()
{
    $this->load->database();
}

public function get_details()
{
$query = $this->db->get_where('users', array('id' => $id));
return $query->row_array();

}
}

I am getting the error message :Undefined property: Navigate::$myaccount_model.

I know its something to do with how I'm passing the users id from the controller to the model?

  • 写回答

3条回答 默认 最新

  • dqpfl2508589 2014-12-22 13:53
    关注

    You need to load the model before using its functions

    $this->myaccount_model->get_details($data);
    $this->load->model('myaccount_model');
    

    to

    $this->load->model('myaccount_model');
    $this->myaccount_model->get_details($session_data['id']);
    

    edit:

    If you want to get details from a specific id (session id), add a parameter in your get_details($id) function located in your model.

    for example:

    public function get_details($id){
       $query = $this->db->get_where('users', array('id' => $id), 1);
       return $query->row_array();
    }
    

    Then call it in your controller like this:

    $result = $this->myaccount_model->get_details($session_data['id']);

    Now pass this $result to your view.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符