doudiyu1639
2018-07-02 13:54
浏览 53
已采纳

CodeIgniter - 配置文件编辑后

I can edit profile edit with SESSION data. But I want to see the change immediately. When I change my profile, I can not see changes in the profile when I edited. When I logout and I again enter login page to the dashboard, I can see. But I want to see quick after edited without login again.

My Controller:

public function update($userId) {
        $maxDim = 100;
        $file_name = $_FILES['userImg']['tmp_name'];
        list($width, $height, $type, $attr) = getimagesize( $file_name );
        if ( $width > $maxDim || $height > $maxDim ) {
            $target_filename = $file_name;
            $ratio = $width/$height;
            if( $ratio > 1) {
                $new_width = $maxDim;
                $new_height = $maxDim/$ratio;
            } else {
                $new_width = $maxDim*$ratio;
                $new_height = $maxDim;
            }
            $src = imagecreatefromstring( file_get_contents( $file_name ) );
            $dst = imagecreatetruecolor( $new_width, $new_height );
            imagecopyresampled( $dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
            imagedestroy( $src );
            imagepng( $dst, $target_filename ); // adjust format as needed
            imagedestroy( $dst );
        }

        if (isset($_FILES) && $_FILES['userImg']['error'] == '0') {
            $config['upload_path'] = './upload/user';
            $config["allowed_types"] = "*";
            $config['max_size']             = 1024;
            $config['max_width']            = 1000;
            $config['max_height']           = 1000;
            $config['overwrite'] = TRUE;
            $new_name = $this->input->post("userUsername");
            $config['file_name'] = $new_name;
            $this->load->library('upload', $config);
            $this->upload->initialize($config);
            if ( ! $this->upload->do_upload('userImg'))
            {
                $error = array('error' => $this->upload->display_errors());
                echo json_encode($error);
            }
            else{
                $upload_data = $this->upload->data();
                $data = array (
                    "userUsername" => $this->input->post("people_username"),
                    "userPass" => $this->input->post("people_pass"),
                    "userEmail" => $this->input->post("people_email"),
                    "userName" => $this->input->post("people_name"),
                    "userSurname" => strtoupper($this->input->post("people_surname")),
                    "userImg" => $upload_data['file_name'],
                    "userLang" => $this->input->post("people_lang"),
                    "userType" => $this->input->post("people_type"),
                    "userModifyDate" => date('Y-m-d H:i:s'),
                );
                $update = $this->db->where("userId", $userId)->update("user", $data);
                if($update) {
                    redirect(base_url("profile"));
                }else {
                    echo "Hata!";
                }
            }
        }
        else{
            $data = array (
                "userUsername" => $this->input->post("people_username"),
                "userPass" => $this->input->post("people_pass"),
                "userEmail" => $this->input->post("people_email"),
                "userName" => $this->input->post("people_name"),
                "userSurname" => strtoupper($this->input->post("people_surname")),
                "userLang" => $this->input->post("people_lang"),
                "userType" => $this->input->post("people_type"),
                "userModifyDate" => date('Y-m-d H:i:s'),
            );
            $update = $this->db->where("userId", $userId)->update("user", $data);
            if($update) {
                redirect(base_url("profile"));
            }else {
                echo "Hata!";
            }
        }
    }

My View:

<div class="panel-body bio-graph-info">
                        <h1> <?php echo $this->lang->line('profile_edit_text_informations'); ?></h1>
                        <form class="form-horizontal" role="form" method="post" action="<?php echo base_url('profile/update/'.$this->session->userdata('people_id')); ?>">
                            <div class="form-group" hidden>
                                <label  class="col-lg-2 control-label"><?php echo $this->lang->line('profile_first_name'); ?></label>
                                <div class="col-lg-6">
                                    <input type="text" class="form-control" id="f-name" name="userId" placeholder="<?php echo $this->session->userdata('people_Id'); ?>" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-lg-2 control-label">Change Avatar</label>
                                <div class="col-lg-6">
                                    <input type="file" class="file-pos" id="exampleInputFile" name="userImg">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-lg-2 control-label"><?php echo $this->lang->line('profile_first_name'); ?></label>
                                <div class="col-lg-6">
                                    <input type="text" class="form-control" id="f-name" name="people_name" placeholder="<?php echo $this->session->userdata('people_name'); ?>" value="<?php echo $this->session->userdata('people_name'); ?>" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-lg-2 control-label"><?php echo $this->lang->line('profile_last_name'); ?></label>
                                <div class="col-lg-6">
                                    <input type="text" class="form-control" id="l-name" name="people_surname" placeholder="<?php echo $this->session->userdata('people_surname'); ?>" value="<?php echo $this->session->userdata('people_surname'); ?>" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-lg-2 control-label">Office</label>
                                <div class="col-lg-6">
                                    <input type="text" class="form-control" id="c-name" name="userOffice" placeholder="<?php echo 'Bursa' ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-lg-2 control-label">Username</label>
                                <div class="col-lg-6">
                                    <input type="text" class="form-control" id="f-name" name="people_username" placeholder="<?php echo $this->session->userdata('people_username'); ?>" value="<?php echo $this->session->userdata('people_username'); ?>" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-lg-2 control-label">Password</label>
                                <div class="col-lg-6">
                                    <input type="text" class="form-control" id="f-name" name="people_pass" placeholder="<?php echo $this->session->userdata('people_pass'); ?>" value="<?php echo $this->session->userdata('people_pass'); ?>" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-lg-2 control-label">Email</label>
                                <div class="col-lg-6">
                                    <input type="email" class="form-control" id="email" name="people_email" placeholder="<?php echo $this->session->userdata('people_email'); ?>" value="<?php echo $this->session->userdata('people_email'); ?>" />
                                </div>
                            </div>
                            <!-- Basic select -->
                            <div class="form-group">
                                <label class="control-label col-lg-3">Choose Language <span class="text-danger">*</span></label>
                                <div class="col-lg-9">
                                    <select name="people_lang" class="form-control">
                                        <option value="<?php echo $this->session->userdata('people_lang'); ?>" value="<?php echo $this->session->userdata('people_lang'); ?>"><?php echo $this->session->userdata('people_lang'); ?></option>
                                        <option value="en">English</option>
                                        <option value="ar">Arabic</option>
                                    </select>
                                </div>
                            </div>
                            <!-- /basic select -->
                            <!-- Basic select -->
                            <div class="form-group">
                                <label class="control-label col-lg-3">User Type <span class="text-danger">*</span></label>
                                <div class="col-lg-9">
                                    <select name="people_type" class="form-control">
                                        <option value="<?php echo $this->session->userdata('people_type'); ?>"><?php echo $this->session->userdata('people_type'); ?></option>
                                        <option value="1">Admin</option>
                                        <option value="2">Yönetici</option>
                                        <option value="3">Departman Sorumlusu</option>
                                        <option value="4">Operatör</option>
                                        <option value="5">Stajyer</option>
                                    </select>
                                </div>
                            </div>
                            <!-- /basic select -->

                            <div class="form-group">
                                <div class="col-lg-offset-2 col-lg-10">
                                    <button type="submit" class="btn btn-success" value="Upload">Save</button>
                                    <button type="button" class="btn btn-default">Cancel</button>
                                </div>
                            </div>
                        </form>
                    </div>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duangutian1426 2018-07-02 15:19
    已采纳

    You currently using SESSION for showing the data. so you must reset the all SESSION after update of the data. Test this code.

    public function update($userId) {
        $maxDim = 100;
        $file_name = $_FILES['userImg']['tmp_name'];
        list($width, $height, $type, $attr) = getimagesize( $file_name );
        if ( $width > $maxDim || $height > $maxDim ) {
            $target_filename = $file_name;
            $ratio = $width/$height;
            if( $ratio > 1) {
                $new_width = $maxDim;
                $new_height = $maxDim/$ratio;
            } else {
                $new_width = $maxDim*$ratio;
                $new_height = $maxDim;
            }
            $src = imagecreatefromstring( file_get_contents( $file_name ) );
            $dst = imagecreatetruecolor( $new_width, $new_height );
            imagecopyresampled( $dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
            imagedestroy( $src );
            imagepng( $dst, $target_filename ); // adjust format as needed
            imagedestroy( $dst );
        }
    
        if (isset($_FILES) && $_FILES['userImg']['error'] == '0') {
            $config['upload_path'] = './upload/user';
            $config["allowed_types"] = "*";
            $config['max_size']             = 1024;
            $config['max_width']            = 1000;
            $config['max_height']           = 1000;
            $config['overwrite'] = TRUE;
            $new_name = $this->input->post("userUsername");
            $config['file_name'] = $new_name;
            $this->load->library('upload', $config);
            $this->upload->initialize($config);
            if ( ! $this->upload->do_upload('userImg'))
            {
                $error = array('error' => $this->upload->display_errors());
                echo json_encode($error);
            }
            else{
                $upload_data = $this->upload->data();
                $data = array (
                    "userUsername" => $this->input->post("people_username"),
                    "userPass" => $this->input->post("people_pass"),
                    "userEmail" => $this->input->post("people_email"),
                    "userName" => $this->input->post("people_name"),
                    "userSurname" => strtoupper($this->input->post("people_surname")),
                    "userImg" => $upload_data['file_name'],
                    "userLang" => $this->input->post("people_lang"),
                    "userType" => $this->input->post("people_type"),
                    "userModifyDate" => date('Y-m-d H:i:s'),
                );
                $update = $this->db->where("userId", $userId)->update("user", $data);
                if($update) {
                    $this->session->set_userdata('people_username',$this->input->post("people_username"));
                    $this->session->set_userdata('people_pass',$this->input->post("people_pass"));
                    $this->session->set_userdata('people_email',$this->input->post("people_email"));
                    $this->session->set_userdata('people_name',$this->input->post("people_name"));
                    $this->session->set_userdata('people_surname',$this->input->post("people_surname"));
                    $this->session->set_userdata('people_lang',$this->input->post("people_lang"));
                    $this->session->set_userdata('people_type',$this->input->post("people_type"));
    
                    redirect(base_url("profile"));
                }else {
                    echo "Hata!";
                }
            }
        }
        else{
            $data = array (
                "userUsername" => $this->input->post("people_username"),
                "userPass" => $this->input->post("people_pass"),
                "userEmail" => $this->input->post("people_email"),
                "userName" => $this->input->post("people_name"),
                "userSurname" => strtoupper($this->input->post("people_surname")),
                "userLang" => $this->input->post("people_lang"),
                "userType" => $this->input->post("people_type"),
                "userModifyDate" => date('Y-m-d H:i:s'),
            );
    
            $update = $this->db->where("userId", $userId)->update("user", $data);
            if($update) {
                $this->session->set_userdata('people_username',$this->input->post("people_username"));
                $this->session->set_userdata('people_pass',$this->input->post("people_pass"));
                $this->session->set_userdata('people_email',$this->input->post("people_email"));
                $this->session->set_userdata('people_name',$this->input->post("people_name"));
                $this->session->set_userdata('people_surname',$this->input->post("people_surname"));
                $this->session->set_userdata('people_lang',$this->input->post("people_lang"));
                $this->session->set_userdata('people_type',$this->input->post("people_type"));
                redirect(base_url("profile"));
            }else {
                echo "Hata!";
            }
        }
    }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题