CI框架(4)-页面跳转

来源:互联网 发布:js是一种什么语言 编辑:程序博客网 时间:2024/05/19 05:39

1,设置CI框架的初始控制器

2,创建两个页面

3,实现页面跳转


1,设置CI框架的初始控制器

当运行CI项目时,我们所看到的第一个页面是由controller转发的视图,而这个controller我们是在[application]->[config]->[routes.php]进行设置

$route['default_controller'] = 'welcome';

我当前设置的第一个页面是由welcome转发的视图。

2,创建两个页面

(1)首先在[application]->[controllers]目录下创建Page2.PHP

class Page2 extends CI_Controller {    public function index()    {        $this->load->view('page2');    }}

(2)首先在[application]->[view]目录下创建Page2.PHP

<?phpdefined('BASEPATH') OR exit('No direct script access allowed');?><!DOCTYPE html><html lang="en"><head>    <meta charset="utf-8">    <title>page2</title></head><body>   <h1 >page2</h1></body></html>

3,实现页面跳转

(1)在[application]->[controllers]->[Welcome.php]
添加代码$this->load->helper(‘url’);

class Welcome extends CI_Controller {    function Welcome(){        parent::__construct();        $this->load->helper('url');    }    public function index()    {        $this->load->view('welcome');    }}

(2)在[application]->[views]->[welcome.php]页面添加js代码

<html lang="en"><head>    <meta charset="utf-8">    <title>第一个页面</title>    <script type="text/javascript">        function turnto(){            var url = "<?php echo site_url('Page2')?>";            window.location.href=url;        }    </script></head><body>   <h1 onclick="turnto()">hello student</h1></body></html>
原创粉丝点击