关于CI的其他信息我就不对说,我们直接进入正题,CI框架应用。
一.配置CI框架
先从官网下载CI框架包,只有2M多网址为http://codeigniter.org.cn/点击下载就行
下载后解压,目录如下
Application是应用程序目录,网站的控制器、视图、模型什么的都放在里面
System文件里面的东西不要修改,看一下就好
User_guide用户手册,全英文版的,一般的解决办法是删了
Index.php是网站入口,有时候会有一些路径在这里配置
在服务器网站根目录下建一个文件夹,把里面的文件都复制过去
修改一下application/config/config.php文件
修改一下$config[‘base_url’] = ‘localhost/penderie’;(不修改也可以)
这样就配置好了
现在访问试一下:在浏览器地址栏输入http://localhost/penderie/
显示
2.控制器认识
Controller是框架控制器文件夹
我们来写一下自己的控制器,控制器文件名要和类名一直,类名首字母大写
test.php文件代码
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller{
public function hello()
{
echo "hello world!";
}
public function welcome()
{
echo "welcome to you!";
}
}
访问此控制器时,标准路径是http://localhost/penderie/index.php/test/hello
http://localhost/penderie/index.php是入口
test是控制器名,hello是方法名
有时候不写方法名会出现404错误,所以还是规范点全部写上吧
3用控制器访问view
view文件下test.php代码
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller{
public function hello()
{
echo "hello world!";
}
public function welcome()
{
echo "welcome to you!";
}
public function toview()
{
$this->load->view('test');
}
}
view文件下test.html代码
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<body>
这是html文件
</body>
</html>
通过http://localhost/penderie/index.php/test/toview路径访问
当方法
public function toview()
{
$this->load->view('test');
}
view(‘test’);里面不加html时访问的是test.php
当view(‘test.html’);里面加html时访问的是test.html
今天就学这么多,model内容比较多等下次再讲吧