簡體   English   中英

使用bootstrap codeigniter從控制器發送數據到彈出模式

[英]Send data from controller to pop up modal using bootstrap codeigniter

您好我打算使用模態引導程序做一個忘記密碼功能..在我沒有彈出模式之前我做了..我知道如何傳遞數據..但現在我不知道如何從控制器發送數據彈出模式..

這是我的代碼:

    <div id="forgot-password" class="modal hide fade in" style="display: none; ">
            <div class="modal-header" style="background-color:#f39c12; color:#fff;">
                <h3 id="helpModalLabel"> Forgot Password</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal well" method="post" id="forgot_form" action="<?php echo base_url(); ?>forgotpassword/doforget">
                    <fieldset>
                        <legend></legend>
                            <div class="control-group">
                            <?php if( isset($info)): ?>

                                <div class="alert alert-block alert-success fade in" id="alert-message" >
                                    <img src="<?php echo base_url("assets")?>/image/Done.png" width="20px" height="20px">
                                    <button type="button" class="close" data-dismiss="alert">&times;</button>
                                    <?php echo($info) ?>
                                </div>
                            <?php elseif( isset($error)): ?>
                                <div class="alert alert-block alert-error fade in" id="alert-message">
                                <img src="<?php echo base_url("assets")?>/img/icon/warning.png" width="20px" height="20px">
                                <button type="button" class="close" data-dismiss="alert">&times;</button>
                                    <?php echo($error) ?>
                                </div>
                            <?php endif; ?>
                                <label for="Username" class="control-label span3" >Username</label>
                                <div class="controls">
                                    <input class="span3" type="text" id="Username" name="Username" placeholder="Input the Registered Username" name="Username"/>
                                    <span id="UsernamehelpText"></span>
                                </div>

                            </div>
                            <div class="form-actions">
                                <input type="submit" class="btn btn-primary" value="Send Password" name="submitbtn"/>


                            </div>

                    </fieldset>
                </form>
            </div>
            <div class="modal-footer">
              <a href="#" class="btn btn-primary round" data-dismiss="modal">Close</a>
            </div>
        </div>

調節器

public function forget()
{
    if (isset($_GET['info'])) {
           $data['info'] = $_GET['info'];
          }
    if (isset($_GET['error'])) {
          $data['error'] = $_GET['error'];
          }

    $page_content["page_title"] = "";
    $page_content["title"] = "Forgot Password";
    $page_content["icon_title"] = "home";

    $menu_params["sub_current_navigable"] = "";
    $page_content["navmenu"] = $this->load->view("nav_menu", "", true);
    $page_content["menu"] = $this->load->view("main_menu_login", $menu_params, true);
    if(isset($data)){
    $page_content["content"] = $this->load->view("forgotpassword",$data, true);
    }else{
    $page_content["content"] = $this->load->view("forgotpassword","", true);
    }
    $this->load->view("template/main_template", $page_content);
}


    public function doforget()
{
    $this->load->helper('url');
    $username= $_POST['Username'];
    $checkuser = $this->forgotpassword_model->getusername($username);
    print_r($checkuser);
    $getemail = $this->forgotpassword_model->getemail($username);
    if(!empty($checkuser))
    {
        $user = $checkuser['0'];
        $email = $getemail['0'];
        if(!empty($email['email']))
        {
            $this->sendpassword($user,$email);
            $info= "Password has been reset and has been sent to email id: ". $email['email'];
            echo $info;
            redirect('login/forget?info='.$info, 'refresh');
        }else{
            $error = "You don't have email, please contact your admin library ";
            echo $error;
            redirect('login/forget?error=' . $error, 'refresh');
         }
    }else
    {
        $error= "You have input wrong username ";
        redirect('login/forget?error=' . $error, 'refresh');
        echo $error;
    }

} 

有人可以幫助我將其遷移到彈出模式嗎? 我需要ajax嗎? 我也想發送錯誤信息彈出模態..現在我正在使用'login / forget?error ='。 $ error,'refresh')我仍然可以使用它嗎?

編輯

要將數據從Controller傳遞到bootstrap模式,你需要json 這樣做試試這個:

在你的控制器中

 $this->output->set_content_type('application/json');
 $this->output->set_output(json_encode(  $your_data_array ));

此代碼將您的數組數據更改為JSON,然后將其發送到您調用此方法的任何內容。 使用您的AJAX調用此方法並成功獲取此數據使用JSON.pars()方法解析它並將它們放入您的模態。


在CodeIgniter中,在使用模型之前,您需要加載它。 例如,您在名為userAuth 模型文件夾中編寫模型。 創建模型如下:

public function forgetPass( $data1, $data2, $data3){
//your code
}

在你的模型中,你可以使用像forgetPass這樣的方法來為你提供一個數組或數據,如:

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

要么

$this->userAuth->forgetPass($data);

如果要在控制器方法中使用模型,可以在控制器方法中輕松加載它,或者將其加載到控制器構造函數中,如下所示:

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

當您需要這樣的方法時,根據給出的示例,您可以將數據傳遞給它:

 $this->userAuth->forgetPass($data); 

加成:

在CodeIgniter中,我們有內置的方法來獲取POST / GET數據。 它們易於使用且更安全。 您可以使用:

 $variable = $this->input->post('your_input_name'); 

要么

 $variable = $this->input->get('your_key'); 

而不是$_GET['your_key']$_POST['your_input_name']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM