CodeIgniter从视图页面重定向到另一个视图页面

时间:2015-09-16 10:59:22

标签: php codeigniter model-view-controller

我目前正在使用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);
 }

由于

3 个答案:

答案 0 :(得分:0)

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

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

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

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

答案 1 :(得分:0)

使用活动记录

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

答案 2 :(得分:0)

您可以使用CodeIgniter中的redirect方法在页面视图之间切换。然后为每个页面表单添加<?php echo site_url('controller_class/Controller_funtion');?>。然后,您必须执行2个控制器功能, 1.对于$this->load->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);