<?php
class Form_demo extends CI_Controller {
	public function index() {
	}
	// http://127.0.0.1:8000/CodeIgniter-3.0.0/form_demo/insert
	public function insert() {
		$this->load->helper ( array ('form','url') );
		//加载模块
		$this->load->library ( 'form_validation' );
		
		// 研制如果这样编写会编写很多规则代码.可以在config进行配置验证文件.
		// $this->form_validation->set_rules('name','用户名','required');
		// $this->form_validation->set_rules('password','密码','required');
		// $this->form_validation->set_rules('email','邮箱',array('required','valid_email'));
		// // 表单验证
		// $bool = $this->form_validation->run();
		
		// 表单验证配置文件 application/config/form_validation.php
		$bool = $this->form_validation->run('demo');
		if ($bool) {
			// 调用模型保存数据库
			echo 'success';
		} else {
			// 显示错误信息
			$this->load->view ( 'user/form_view_demo' );
		}
		
		echo $bool;
	}
}