从控制器发送数据弹出模态使用引导代码指示器 [英] Send data from controller to pop up modal using bootstrap codeigniter

查看:110
本文介绍了从控制器发送数据弹出模态使用引导代码指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我要做一个忘记密码函数使用模态的引导..
之前,我没有弹出模态..我知道如何传递数据..
,但现在我不知道如何从控制器发送数据以弹出模态..



这是我的代码:

 < div id =forgot-passwordclass =modal hide fade instyle =display:none;> 
< div class =modal-headerstyle =background-color:#f39c12; color:#fff;>
< h3 id =helpModalLabel>忘记密码< / h3>
< / div>
< div class =modal-body>
< form class =form-horizo​​ntal wellmethod =postid =forgot_formaction =<?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 inid =alert-message>
< img src =<?php echo base_url(assets)?> /image/Done.pngwidth =20pxheight =20px>
< button type =buttonclass =closedata-dismiss =alert>& times;< / button>
<?php echo($ info)?>
< / div>
<?php elseif(isset($ error)):?>
< div class =alert alert-block alert-error fade inid =alert-message>
< img src =<?php echo base_url(assets)?> /img/icon/warning.pngwidth =20pxheight =20px>
< button type =buttonclass =closedata-dismiss =alert>& times;< / button>
<?php echo($ error)?>
< / div>
<?php endif; ?>
< label for =Usernameclass =control-label span3>用户名< / label>
< div class =controls>
< input class =span3type =textid =Usernamename =Usernameplaceholder =输入注册用户名name =用户名
< span id =UsernamehelpText>< / span>
< / div>

< / div>
< div class =form-actions>
< input type =submitclass =btn btn-primaryvalue =Send Passwordname =submitbtn/>


< / div>

< / fieldset>
< / form>
< / div>
< div class =modal-footer>
< a href =#class =btn btn-primary rounddata-dismiss =modal>关闭< / 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] =忘记密码;
$ page_content [icon_title] =家;

$ 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 =密码已重置,并已发送到电子邮件ID:。 $ email ['email'];
echo $ info;
redirect('login / forget?info ='。$ info,'refresh');
} else {
$ error =您没有电子邮件,请与您的管理员库联系;
echo $ error;
redirect('login / forget?error ='。$ error,'refresh');
}
} else
{
$ error =您输入了错误的用户名;
redirect('login / forget?error ='。$ error,'refresh');
echo $ error;
}

}

有人可以帮我迁移弹出模态?我需要ajax吗?
我也想发送错误消息弹出模态..
现在我使用'login / forget?error ='。

解决方案

编辑



将您的数据从控制器传递到引导模式,您需要强>。



 

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

此代码将您的数组数据更改为JSON,然后将其发送到任何调用此方法。你的AJAX调用这个方法,并在成功获得这个数据解析它与 JSON.pars()方法,并把他们到你的模态。





在CodeIgniter中,在使用模型之前,需要加载它。例如,您在模型文件夹中编写名为 userAuth 的模型。创建模型如下:

 类UserAuth扩展CI_Model {
//你的方法
}

在你的模型中,你可以使用 forgetPass 将给你一个数组或数据,如:

  public function forgetPass($ dataArray){
// your代码
}

  public function forgetPass($ data1,$ data2,$ data3){
//你的代码
}

当你想在控制器方法中使用你的模型时,你可以在控制器方法中加载它,或者在控制器构造函数this:

  $ 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']


Hello I was going to make a forgot password function using modal bootstrap.. before I have made it without pop up modal.. I do know how to pass the data.. but now I don't know how to send data from controller to pop up modal..

Here is my code:

    <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>

Controller

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;
    }

} 

Can someone help me to migrate this to pop up modal? do I need ajax? I also want to send the error message to pop up modal.. now I'm using 'login/forget?error=' . $error, 'refresh') Is it possible for me for still using this?

解决方案

EDIT

to pass your data from Controller to bootstrap modal you need json. to do that try this:

in your controller

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

this code change your array data to JSON and then send it to whatever you call this method. with your AJAX call this method and in success get this data parse it with JSON.pars() method and put them to your modal.


In CodeIgniter, before using a model you need to load it. For example you write a model in model folder with name userAuth. Creating a model is as follows:

class UserAuth extends CI_Model{
   //your methods
}

In your model you can have some method like forgetPass that will give you an array or data like:

public function forgetPass($dataArray){
 //your Code
}

OR

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

When you want to use your model in a controller method you can load it handily in your controller method or load it in controller constructor like this:

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

When you need a method like that, according to the example given you can pass your data to it as:

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

addition:

In CodeIgniter, we have in-built methods to get POST / GET data. They are easy to use and safer. You can use:

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

OR

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

Instead of $_GET['your_key'] or $_POST['your_input_name']

这篇关于从控制器发送数据弹出模态使用引导代码指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆