今天起学习CI框架--写了一个很不完善注册页面

这个星期是实训周,任务很艰巨,要我们学习CI框架然后学一个网站。

今天很完一些手册后,写了一个很不完善注册页面,post出来,大家提提意见。(本人是菜鸟,勿怪!)

首先在配置文件夹的database.phpp配置数据库 (这个大家都知道的)

然后view视图文件中建立一个文件V_reg.php,代码如下:

<html>
<head><title>注册界面</title></head>
<body>
<form method="post" accept-charset="utf-8" action="reg"/>

<label for="user_name">用户名:</label>

<input type="input" name="user_name" /><br />

<label for="user_pass">设置密码:</label>

<input type="password" name="user_pass" /><br />


<label for="user_pass2">重复密码</label>
<input type="password" name="user_pass2" /><br />

<label for="user_email">电子邮箱</label>
<input type="input" name="user_email" /><br />

<label for="user_phone_num">手机号码:</label>
<input type="input" name="user_phone_num" /><br />

<input type="submit" name="submit" value="Create news item" />

</form>
</body>
</html>

 

然后,然后在数据模型文件夹中,建立M_reg,代码如下

<?php
/*
* Created on 2012-7-2
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class M_reg extends CI_Model {
function __construct(){
parent::__construct();
$this->load->database();
}
public function set_Admin()
{
// $this->load->helper('url');

//$slug = url_title($this->input->post('title'), 'dash', TRUE);

$data = array(
'user_name' => $this->input->post('user_name'),
'user_pass' => $this->input->post('user_pass'),
'user_email' => $this->input->post('user_email'),
'user_phone_num'=>$this->input->post('user_phone_num'),
);

return $this->db->insert('gs_users', $data);
}

}
?>

然后就是在控制器文件夹中,建立C_reg,代码如下:

<?php
/*
* Created on 2012-7-2
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class C_reg extends CI_Controller{

public function __construct()
{
parent::__construct();
$this->load->model('M_reg');
}


public function reg(){
$this->load->helper('form');
$this->load->library('form_validation');

$data['title'] = '注册';

$this->form_validation->set_rules('user_name', '用户名', 'required');
$this->form_validation->set_rules('user_pass', '密码', 'required');
$this->form_validation->set_rules('user_email', '邮箱', 'required');
$this->form_validation->set_rules('user_phone_num', '电话', 'required');

// $this->load->view('V_reg');
if ($this->form_validation->run() === FALSE)
{
// $this->load->view('templates/header', $data);
$this->load->view('V_reg');
// $this->load->view('templates/footer');

}
else
{
//$this->M_reg->set_Admin();
$this->M_reg->set_Admin();
//$this->load->view('V_reg');
}

}

}
?>

第一次发表此类文章,希望大家不要吝啬赐教!!哈哈

也希望更多高手发一些CI框架教程来教我们这些菜鸟,谢谢!

posted @ 2012-07-02 21:50  morongrong  阅读(265)  评论(0编辑  收藏  举报