Use PHP Development HR system (3)

   

In this section we describe how to create a home page.

==================================================================================================

We begin to understand the CI operating mechanism framework, the following are CI introduction on the official website:

The figure shows the data flow of the system:

  1. index.php file as a front-end controller, basic resources required to initialize operation CodeIgniter;
  2. Router checks the HTTP request, to determine how to handle the request;
  3. If the cache file exists, the output directly to the browser, do not go below the normal system processes;
  4. Before loading the application controller, an HTTP request and any user-submitted data security checks;
  5. Loading the controller model, the core library, a helper, and all other resources required to process the request;
  6. The final step, rendering the view and sent to the browser, if the cache is turned on, the view will first be cached for subsequent requests.

来自 <https://codeigniter.org.cn/user_guide/overview/appflow.html>

   

1 Modify the CI profiles

1) Open application-> config-> routes.php file;

See $ route [ 'default_controller'] = 'welcome'; default controller shown here are available for purchase , we modify the main

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

2、创建main控制器及页面

由上面的配置文件我们可以看出,我们需要名称为main的控制器,打开application->controllers文件夹,看到目录下

有一个Welcome.php的文件,这个就是系统默认调用的文件;

   

1)在application->controllers目录下新建Main.php文件,输入以下代码:

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

   

class Main extends CI_Controller {

   

public function index()

{

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

}

}

   

2)在application->view目录下新疆main_list.php文件,也就是上面方法中调用的这个文件,输入代码:

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

?><!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>This is my main page</title>

</head>

<body>

   

<div id="container">

<h1>This is my main page!</h1>

   

<div id="body">

<p>This is my main page.</p>

</div>                

</div>

   

</body>

</html>

   

3 运行测试

运行发现主页已经变成了main_list.php的内容了,表示我们的主页就创建成功了;

   

总结:

本节我们通过修改配置文件,及创建控制器与视图页面,初步完成了主页的创建工作,这里需要充分理解CIMVC机制,

以及熟悉CI框架配置文件的内容。虽然主页已经创建成功了,但是目前的主页并没有什么用处,我们还需要创建一个真正好看

能用的主页来满足我们的需求,敬请期待下节。

   

====================================The End==========================

   

   

   

 

   

   

   

   

   

   

   

   

   

   

   

   

 

Guess you like

Origin www.cnblogs.com/zsnzsn/p/11111103.html