个性化阅读
专注于IT技术分析

在CodeIgniter中创建基本站点

在这里, 我们将学习如何在CodeIgniter的帮助下创建一个基本站点。

在controllers文件夹中, 我们将创建一个名为Form.php的文件。

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

class Form extends CI_Controller {

	public function index()
	{
		$this->load->view('header');
		$this->load->view('nav');
		$this->load->view('content');
		$this->load->view('footer');
	}
}	
?>

我们为页眉, 导航, 内容和页脚创建了不同的文件, 所有这些文件均已加载到contoller的文件中。

应用程序/视图中的文件header.php

<!DOCTYPE html>
<html>
<head>
	<title>Basic Site</title>
	<style type="text/css">
		
		body, html{margin:0; padding:0;}

		body{
			background-color:#eee;
		}
		h1, h2, h3, h4, p, a, li, ul{
			font-family: arial, sans-serif;
			color: black;
			text-decoration: none;
		}
		#nav{
			margin: 50px auto 0 auto;
			width: 10000px;
			background-color: #888;
			height: 15px;
			padding: 20px;
		}

		#nav a:hover{
			color: red;

		}
		#nav ul{
			list-style: none;
			float: left;
			margin: 0 50px;
		}

		#nav ul li{
			display: inline;
		}

		#content{
			width: 1000px;
			min-height: 100%;
			margin: 0 auto;
			padding: 20px;
		}

		#footer{
			width: 400px;
			height: 15px;
			margin: 0 auto;
			padding: 20px;
		}

		#footer p{
			color: #777;
		}
	</style>
</head>

在应用程序/视图中文件nav.php

<body>
<div id="container">
	<div id="nav">
		<ul>
			<li><a href="#">Home</a></li>
			<li><a href="#">About Us</a></li>
			<li><a href="#">Contact Us</a></li>
			<li><a href="#">Career</a></li>
		</ul>
	</div>

在application / views中的文件content.php

<div id="content">
		<h1>Welcome to my site</h1>
		<p>CodeIgniter is PHP driven framework but it's not a PHP substitute. 
		Diving into CodeIgniter doesn?t mean you are leaving PHP behind. 
		PHP is a server-side scripting language for building dynamic web-based applications.</p>
</div>

在应用程序/视图中的文件footer.php

<div id="footer">
		<p>Copyright (c) 2016 ABWorld.com All Rights Reserved</p>
	</div>

</div>
</body>
</html>

最终输出如下所示, URL为localhost / site_example / index.php / Form。

Codeignter 7中的Codeigniter Basic网站创建
赞(0)
未经允许不得转载:srcmini » 在CodeIgniter中创建基本站点

评论 抢沙发

评论前必须登录!