【发布时间】:2011-06-02 17:52:54
【问题描述】:
在我名为Profile_model 的模型中,我有这个函数可以检索登录用户的配置文件数据。
function profile_read()
{
$this->db->where('user_id', $this->tank_auth->get_user_id());
$query = $this->db->get('user_profiles');
$data['row'] = $query->row();
}
在我的控制器中,我使用$this->load->view('profile/edit_general_view', $data); 尝试将模型中的数据加载到视图中。
function edit_profile()
{
//validation rules
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required|xss_clean|min_length[2]|max_length[20]|alpha');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|xss_clean|min_length[2]|max_length[20]|alpha');
if ($this->form_validation->run() == FALSE) //if validation rule fails
{
$this->load->view('profile/edit_general_view', $data); //load data from model in view
}
else //success
{
$send_to_db = array (
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name')
);
$seg = 'edit';
$this->load->model('Profile_model');
$this->Profile_model->profile_update($send_to_db, $seg);
}
}
将数据从模型函数profile_read 传递到我的控制器函数的正确方法是什么?
【问题讨论】:
标签: php mysql codeigniter