设置值默认codeigniter

时间:2014-02-19 09:37:22

标签: php codeigniter

我有这个功能(get_profile_info)

function get_profile_info()
{
    $this->db->where('username',$this->session->userdata('username'));
    $get_profile_info = $this->db->get('memberships');
    if($get_profile_info->num_rows() == 1){
        foreach ($get_profile_info->result() as $row)
    {
        echo $row->firstname;
        echo $row->lastname;
    }
        }   
}

问题是如何将此结果:firstname和lastname转换为输入形式默认set_value:echo "Firstname".form_input('firstname2');

3 个答案:

答案 0 :(得分:0)

试试这段代码:

 foreach($get_profile_info->result() as $row)
    {
        $data = array(
              'name'        => 'firstname',
              'id'          => 'firstname',
              'value'       => $row->firstname,              
            );
        echo form_input($data);
       // do the same for lastname
    }

答案 1 :(得分:0)

像这样设置视图文件的输入值。

<input type="text" value="<?php echo $data['firstname']; ?>" />

你必须从控制器传递数据数组。

答案 2 :(得分:0)

试试这个

function get_profile_info()  
{
    $this->db->where('username',$this->session->userdata('username'));
    $get_profile_info = $this->db->get('memberships');
    if($get_profile_info->num_rows() == 1){
        return $get_profile_info->row();      
}
function your_controller
{
     $data['row'] = get_profile_infor()

     $this->load->view("yourview",$data)
}

在视图中

<input type="text" name="firstname" value="<?php echo set_value('firstname',$row->firstname)?>" />
<input type="text" name="lastname" value="<?php echo set_value('lastname',$row->lastname)?>" />