php codeigniter中的用户配置文件

php codeigniter中的用户配置文件,php,codeigniter,user-profile,Php,Codeigniter,User Profile,我试图从“profile\u details”表中获取我的用户信息,并在profile.php视图中显示。 下面是我的Profile.php控制器,它现在只显示视图 <?php class Profile extends CI_Controller { function __construct() { parent::__construct(); } function index() { $this->load->view('admin/pro

我试图从“profile\u details”表中获取我的用户信息,并在profile.php视图中显示。 下面是我的Profile.php控制器,它现在只显示视图

<?php
class Profile extends CI_Controller
{
 function __construct()
 {
     parent::__construct();  

 }

function index()
{

    $this->load->view('admin/profile/index');
}
 
}

一个问题:您是要获取所有用户,还是只获取您放在视图中的身份验证用户??好吧,让我解释一下如何制作myProfile(验证用户)

假设您尚未插入会话用户数据

您的模型应该是这样的:

<?php
class Profile_model extends CI_Model
{

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


function myProfileDetails($username)
{

$query=$this->db->query("SELECT first_name, last_name, email, mobile_no, role, company_name, username FROM profile_details WHERE username = '$username'");
return $query->row();

}

}  

姓
电子邮件Id
电话
子公司名称
角色

就是这样。

您永远不应该存储未加密的密码!您还可以接受SQL注入。这意味着每个对SQL注入知之甚少的人都可以访问所有用户的详细信息和未加密的密码。你有50%的路要走。这在《CI 3用户指南》中有明确的解释。所以你最好先读一读。是的,这不是我现在的问题,我已经在login.php controller中加密了我的密码,我这里的问题是如何在用户配置文件中获取用户信息(除了密码和用户名),我已经修改了controller部分。
 <div class="tab-content profile-tab" id="myTabContent">
                    <div class="tab-pane fade show active" id="About" role="tabpanel" aria-labelledby="home-tab">
                        <div class="row">
                          
                           <div class="form-group col-md-6">
                              <label>First Name</label>
                              <span class="form-control"></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Last Name</label>
                              <span class="form-control">3</span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Email Id</label>
                              <span class="form-control">f</span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Phone</label>
                              <span class="form-control">f</span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Sub-Company Name</label>
                              <span class="form-control">g</span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Role</label>
                              <span class="form-control">t</span>
                            </div>
                    </div>
                        
                </div>
<?php
class Profile_model extends CI_Model
{

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


function myProfileDetails($username)
{

$query=$this->db->query("SELECT first_name, last_name, email, mobile_no, role, company_name, username FROM profile_details WHERE username = '$username'");
return $query->row();

}

}  
<?php
class Profile extends CI_Controller
{
 function __construct()
 {
     parent::__construct();  
     $this->load->model('Profile_model');

 }

function index()
{

// this is your session:::
    $user_id = 48 // this is your id, roxana
// or
    $username = 'admin';
//::::::::::::::::::::::::
 
    $data['my_profiles'] = $this->Profile_model->myProfileDetails($username); // my_profiles will become your view variable to fetch data basesd on its column name
    $this->load->view('admin/profile/index',$data);
}
 
}

<div class="tab-content profile-tab" id="myTabContent">
                    <div class="tab-pane fade show active" id="About" role="tabpanel" aria-labelledby="home-tab">
                        <div class="row">
                          
                           <div class="form-group col-md-6">
                              <label>First Name</label>
                              <span class="form-control"><?= $my_profiles->firstname ?></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Last Name</label>
                              <span class="form-control"><?= $my_profiles->lastname ?></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Email Id</label>
                              <span class="form-control"><?= $my_profiles->email ?></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Phone</label>
                              <span class="form-control"><?= $my_profiles->mobile_no ?></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Sub-Company Name</label>
                              <span class="form-control"><?= $my_profiles->company_name ?></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Role</label>
                              <span class="form-control"><?= $my_profiles->role ?></span>
                            </div>
                    </div>
                        
                </div>