Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter:集成离子认证屏幕和引导模式_Php_Codeigniter_Twitter Bootstrap_Ion Auth - Fatal编程技术网

Php Codeigniter:集成离子认证屏幕和引导模式

Php Codeigniter:集成离子认证屏幕和引导模式,php,codeigniter,twitter-bootstrap,ion-auth,Php,Codeigniter,Twitter Bootstrap,Ion Auth,若用户单击页面上的任何链接,我将检查用户是否以控制器方法登录。如果他未登录,则我会在屏幕上显示登录屏幕模式。 到目前为止一切正常。 如果用户输入了错误的用户名和密码。下一页显示为没有任何CSS的新页。 如何将结果返回到模式登录屏幕? view/index.php $('.index-product img').click(function() { var product = $('<div id="modal-productDetail" class="modal hi

若用户单击页面上的任何链接,我将检查用户是否以控制器方法登录。如果他未登录,则我会在屏幕上显示登录屏幕模式。
到目前为止一切正常。
如果用户输入了错误的用户名和密码。下一页显示为没有任何CSS的新页。
如何将结果返回到模式登录屏幕?
view/index.php

$('.index-product img').click(function() {
          var product = $('<div id="modal-productDetail" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>');           
            $.ajax({
              url: "<?php echo site_url('gallery/openProductDetail');?>",
              type: 'POST',
              success: function(msg) {
                product.html(msg);
                product.modal('show');
              }
             });     
      });
<div class="modal-header">
    <h4 id="myModalLabel">Login To Your Account</h4>
  </div>
  <div id="loginModal" class="modal-body">
    <div class="row">
      <?php echo form_open("auth/login");?>
      <div class="span3">
        <ul class="unstyled" id="emailLogin">
          <li><small class="muted">Login with your email</small></li>
          <?php echo form_open("auth/login");?>
          <li>
            <input name="identity" value="" id="identity" type="text" placeholder="Email Address"/>
            <span class="help-block" id="emailError" style="display:none;"></span>
          </li>
          <li>
            <input name="password" value="" id="password" type="password" placeholder="Password"/>
            <span class="help-block" id="passwordError" style="display:none;"></span>
          </li>
          <li>
            <input style="display:none;" name="remember" value="1" id="remember" type="checkbox">
          </li>
          <li>
            <a class="text-info" id="accountProblem" href="auth/forgot_password">Account problem?</a>
            <input class="loginButton" type="submit"  name="submit" value="Login">
            <?php echo form_close();?>
          </li>
          <li>
            <div id="infoMessage"><?php echo $message;?></div>
          </li>
        </ul>
      </div>
    </div>
  </div>
查看/login.php

$('.index-product img').click(function() {
          var product = $('<div id="modal-productDetail" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>');           
            $.ajax({
              url: "<?php echo site_url('gallery/openProductDetail');?>",
              type: 'POST',
              success: function(msg) {
                product.html(msg);
                product.modal('show');
              }
             });     
      });
<div class="modal-header">
    <h4 id="myModalLabel">Login To Your Account</h4>
  </div>
  <div id="loginModal" class="modal-body">
    <div class="row">
      <?php echo form_open("auth/login");?>
      <div class="span3">
        <ul class="unstyled" id="emailLogin">
          <li><small class="muted">Login with your email</small></li>
          <?php echo form_open("auth/login");?>
          <li>
            <input name="identity" value="" id="identity" type="text" placeholder="Email Address"/>
            <span class="help-block" id="emailError" style="display:none;"></span>
          </li>
          <li>
            <input name="password" value="" id="password" type="password" placeholder="Password"/>
            <span class="help-block" id="passwordError" style="display:none;"></span>
          </li>
          <li>
            <input style="display:none;" name="remember" value="1" id="remember" type="checkbox">
          </li>
          <li>
            <a class="text-info" id="accountProblem" href="auth/forgot_password">Account problem?</a>
            <input class="loginButton" type="submit"  name="submit" value="Login">
            <?php echo form_close();?>
          </li>
          <li>
            <div id="infoMessage"><?php echo $message;?></div>
          </li>
        </ul>
      </div>
    </div>
  </div>

登录到您的帐户
  • 使用您的电子邮件登录

您需要更改
application/controllers/auth.php
中的
login()
方法。 我想您需要在重定向调用之前添加到
login()
方法,如下所示:

    $location = '';
    if($this->form_validation->run() == true)
    {
        //check to see if the user is logging in
        //check for "remember me"
        $remember = (bool) $this->input->post('remember');
        if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember))
        {
            //if the login is successful
            //redirect them back to the home page
            $this->session->set_flashdata('message', $this->ion_auth->messages());
            $data = $this->ion_auth->messages();
            $location = '/';
        }
        else
        {
            $this->session->set_flashdata('message', $this->ion_auth->errors());
            $data = $this->ion_auth->errors();
            $location = 'auth/login';
        }
    }
    else
    {
        $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

        $this->data['identity'] = array('name' => 'identity',
            'id' => 'identity',
            'type' => 'text',
            'value' => $this->form_validation->set_value('identity'),
        );
        $this->data['password'] = array('name' => 'password',
            'id' => 'password',
            'type' => 'password',
        );

        $data = $this->data;
    }

    if($this->input->is_ajax_request())
    {
        echo json_encode(array('data' => $data));
    }
    else
    {
        ($location) ? redirect($location, 'refresh') : $this->_render_page('auth/login', $data);
    }

并添加js代码来处理来自
login()
方法的响应

对于任何ajax请求,它不会返回错误吗?您可以在这里找到
login()
方法抱歉,但我不理解您的评论。我应该在哪里将其添加到
login()
方法?至于我,我会扩展Auth controller并更改
login()
方法,但此解决方案需要更多时间。更简单的解决方案-将
login()
中的所有重定向移动到一个位置,并添加
$this->input->is\u ajax\u request()
检查,但您需要更改
login()的逻辑。请查看我的更新代码。