douhoushou8385 2015-09-30 07:44
浏览 34
已采纳

如何创建一个在codeigniter中创建用户的操作按钮?

I have three users Admin,Reseller and Users. Now Reseller request to admin that he want XYX number of users.

This is saved in a table called User_request Now in admin there is a view where he can see which reseller has requested how many users.

And there is a button Approve or Reject. If Admin hits approve then I want my code to create that much users for that reseller. Now each users is mapped to his/her reseller by a field called key which is unique.

So, when users is created it must store the key of reseller in users table.

Add Users

Now, if approves users that request by re-seller must be deleted. I am very confused what I should be doing here!

The View :

  <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-info">
                    <div class="panel-heading">
                      <h4>New User Requests</h4>
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">


                                <thead>
                                    <tr>
                                        <th>Id</th>
                                        <th>Users Requested</th>
                                        <th>Unique Id</th>
                                        <th>Date Of Request</th>
                                        <th>Approve</th>
                                        <th>Reject</th>
                                        <th>Status</th>
                                    </tr>
                                </thead>


                               <!-- This is where we fetch all records-->

                                <tbody>

                                <?php if(count($users)): foreach($users as $user): ?>

                                    <tr class="odd gradeX">
                                        <td><?php echo  $user->id; ?></td>
                                        <td><?php echo $user->id, $user->user_requested; ?></td>
                                        <td><?php echo $user->id, $user->key; ?></td>
                                        <td><?php echo $user->id, $user->date_requested; ?></td>
                                        <td><a href="reseller/create_user" class="btn btn-primary">Yes&nbsp<i class="glyphicon glyphicon-ok"></i></a></td>
                                        <td><a href="reseller/change_status" class="btn btn-danger">No&nbsp<?php echo'<i class="glyphicon glyphicon-trash"></i>';?></a></td>
                                         <td><a href="" class="btn btn-success"><?php echo  $user->status; ?></td>&nbsp</a></td>

                                    </tr>








                                    <?php endforeach; ?>
                                    <?php else: ?>
                                        <tr>
                                            <td colspan="3">We could not find any users.</td>
                                        </tr>
                                    <?php endif; ?> 



                                </tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->

                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>

The Controller:

      public function create_user()
      {


        $this->load->model('more_m');

        $id = $this->session->userdata('id');

            $this->db->set('status', "'approved'",FALSE);
            $this->db->where('id',$id);
            $this->db->update('user_request');

            redirect('admin/new_user');

      }

Now, I just want to add the code to creates users for the requested Reseller.

  • 写回答

1条回答 默认 最新

  • dongyi6845 2015-09-30 11:37
    关注

    I have succeeded to accomplish this :

          public function create_user()
          {
    
    
                $this->load->model('more_m');
                $id= $this->session->userdata('id');
                $rajan =$this->more_m->get(array('user_requested',$id));
                $request=$rajan->user_requested;        
    
    
                $this->load->model('reseller_m');
    
                $query=$this->db->select('key');
                $query=$this->db->get('reseller');
    
                if($query->num_rows() > 0)
                {
                    $row = $query->row_array();
                    $key= $row['key'];
                }
    
    
    
    
    
                        for($i=1; $i<=$request;$i++)
                            {
    
                            $userdata=array('key'=>$key);
    
                            $this->db->insert('users',$userdata);
    
                            }
    
    
    
    
    
    
                $this->load->model('more_m');
                $id = $this->session->userdata('id');
                $this->db->set('status', "'approved'",FALSE);
                $this->db->where('id',$id);
                $this->db->update('user_request');
    
                redirect('admin/new_user');
    
          }
    

    Firstly I fetch how many users are required then the key and finally loop them and insert the users along with reseller key

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集