【问题标题】:CodeIgniter redirect from a view page to another view pageCodeIgniter 从一个视图页面重定向到另一个视图页面
【发布时间】:2015-12-12 22:18:05
【问题描述】:

我目前正在使用 CodeIgniter 并尝试创建两个表单。 已经完成的用户名/密码的一种形式。 (所以我们假设用户有一个帐户)。 创建帐户的一种形式。(尚未完成)。 我使用我的控制器加载第一个链接,例如

$this->load->view('Login_view');

我遇到的第一个问题是想办法从另一个视图文件中加载一个视图文件? 在我的“Login_view”文件中,我尝试通过这种方式加载另一个视图文件:

<p><a href="<?php echo site_url('index.php/New_account.php')?>">New account</a></p>

或者这样

    <p><a href="http://localhost:8888/CodeIgniter-3.0.0/index.php/New_account.php">New account</a></p>

最后一个

   <p><a href="<?php echo base_url('index.php/New_account.php')?>">New account</a></p>

否则这些都不起作用。那么是否可以从视图文件打开另一个页面,或者唯一的方法是回到我的控制器类并打开所需的视图文件?或者也许这是错误的做法?

这是我的控制器代码的开头(我认为开头是合理的)

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Verifylogin extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->helper->helper('url');
   $this->load->model('user','',TRUE);
 }

谢谢

【问题讨论】:

  • 您在其中编写代码以加载视图的控制器名称是什么??
  • @Saty : 你好,我编辑了我的消息,现在包含我的控制器代码的开头:)

标签: php codeigniter model-view-controller


【解决方案1】:

您可以简单地在控制器中创建注册功能并从中加载视图,例如

  function registration()
  {
    $this->load->view('New_account');
  }

并在登录视图中添加注册链接

<a title="New account" href='<?php echo base_url ('controller_name/registration'); ?>'>New account</a>

【讨论】:

    【解决方案2】:

    使用活动记录

     echo anchor('verifylogin/user', 'New account', 'title="New account"');
    

    确保您上传

    $this->load->helper('url');
    

    控制器

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Verifylogin extends CI_Controller {
    
     function __construct()
     {
       parent::__construct();
       $this->helper->helper('url');
       $this->load->model('user','',TRUE);
    
     }
     function user()
     {
         $this->load->view('New_account');
     }
    }
    

    【讨论】:

      【解决方案3】:

      您可以使用 CodeIgniter 中的重定向方法在页面视图之间切换。然后为每个页面表单添加 &lt;?php echo site_url('controller_class/Controller_funtion');?&gt; 。然后你必须制作2个控制器功能, 1.对于$this-&gt;load-&gt;view('Login'); 2.对于提交表单时应该发生的操作。 例如,

      //用于登录页面加载

      function Login_load(){
            $this->load->view('login');
      }
      
      function LoginLoad(){
           if($this->input->post('submit')){
          //Things should happen when the form is submitted
      
      }
      }
      

      当您需要更改视图时,只需键入您所在的当前功能,

      redirect('Fuction_class/Login_Load', refresh);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-14
        • 2014-02-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多