[PHP]框架CodeIgniter的简单测试源码

23 篇文章 38 订阅
15 篇文章 0 订阅

[PHP]在CodeIgniter中如何利用CSS创建视图

[PHP]如何使用CodeIgniter简化页面

网站地址:http://callmewhy.sinaapp.com/index.php/test

后面加上/testcss是测试CSS表单的页面http://callmewhy.sinaapp.com/index.php/test/testcss

加上testhead是测试头文件的插入:http://callmewhy.sinaapp.com/index.php/test/testhead

下面是以上两个案例的脚本文件。

完整的项目下载

首先是控制器Controller,文件名Test.php(要在config.php中配置)

<?php
class Test extends CI_Controller {
	function __construct()
	{
		//继承父类的构造方法,不写报错
		parent::__construct();
	}

	function index()
	{
		$this->load->view('welcome_view');
	}

	function testHead(){
		//测试head页面的引入
		$data['mytitle'] ="A website monitoring tool";
		$data['mytext'] ="Test!Test!";
		$data['myrobots'] ='noindex,nofollow';
		$data['mywebtitle']='Web monitoring tool';
		$data['base'] =	$this->config->item('base_url');
		$this->load->view('test_head_view',$data);
	}

	function testCss(){
		$data['mytitle'] ="A website monitoring tool";
		$data['mytext'] ="Test!Test!";
		$data['base'] =	$this->config->item('base_url');
		$data['css'] =$this->config->item('test_css');
		$this->load->view('test_css_view',$data);
	}

}
?>

第一个测试CSS引入的view视图,文件名test_css_view.php:

<html>
<head>
<title>WHY's Test Page</title>
<base href="<?php echo"$base";?>">
<link rel="stylesheet" type="text/css" href="<?php echo"$base/$css";?>">
</head>
<body>
<h1><?php echo$mytitle;?></h1>
<p class="test"><?php echo$mytext;?></p>
</body>
</html>


相应的CSS文件,文件名test.css:

h1{
	margin : 5px;
	padding-left : 10px;
	padding-right : 10px;
	background : #ffffff;
	color : blue;
	width : 100%;
	font-size : 36px;
}
.test{
	margin : 5px;
	padding-left : 10px;
	padding-right : 10px;
	background : #ffffff;
	color : red;
	width : 100%;
	font-size : 36px;
}


第二个测试head嵌入的view视图,文件名test_head_view.php:

<html>
<head>
<?php $this->load->view('header_view');?>
</head>
<body>
<h1><?php echo $mytitle;?></h1>
<p><?php echo $mytext;?></p>
</body>
</html>

第三个是head的文件,文件名head_view.php:

<title><?php echo $mywebtitle?></title>
<base href="<?php echo"$base";?>"/>
<meta name="robots"	content="<?php echo $myrobots?>">
<link rel="stylesheet" type="text/css" href="<?php echo"$base/$css";?>"/>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值