|
发表于 2008-10-30 15:53:51
|
显示全部楼层
验证部分我已经自己想办法写好了
控制器部分:
<?php
class Test extends Controller {
function Test(){
parent::Controller();
}
function index(){
$this->load->helper('form');
$this->load->library('validation');
$data['title'] = "Users add.";
$data['headline'] = "Welcome! to User System.";
$this->load->vars($data);
$this->load->view('users');
}
function save(){
$this->load->helper(array('form', 'url'));
$this->load->library('validation');
$this->load->model('Mtest','',TRUE);
$rules['name'] = "required";
$this->validation->set_rules($rules);
if ($this->validation->run() == FALSE){
echo "数据不能为空";
}else{
$this->Mtest->addUser();
redirect('test/thanks','refresh');
}
function thanks(){
echo "<h1>Thank you !</h1>";
}
}
?>
视图页面:
在echo form_open('test/save');之前加上一句<?php echo $this->validation->error_string; ?>就ok了。
本人鸟蛋级,为了这个验证写了将近1天时间,无语。。。 |
|