刀客孩哥 发表于 2011-9-2 14:05:28

ci官网的教程(插入新闻),呵呵

控制器:

public function create()
{
        $this->load->helper('form');
        $this->load->library('form_validation');
       
        $data['title'] = 'Create a news item';
       
        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('text', 'text', 'required');
       
        if ($this->form_validation->run() === FALSE)
        {
                $this->load->view('templates/header', $data);       
                $this->load->view('news/create');
                $this->load->view('templates/footer');
               
        }
        else
        {
                $this->news_model->set_news();
                $this->load->view('news/success');
        }
}


model:

public function set_news()
{
        $this->load->helper('url');
       
        $slug = url_title($this->input->post('title'), 'dash', TRUE);
       
        $data = array(
                'title' => $this->input->post('title'),
                'slug' => $slug,
                'text' => $this->input->post('text')
        );
       
        return $this->db->insert('news', $data);
}



相对我以前的把输入和验证捆一起的做法

这种形式好像挺清晰的,把验证和插入分开了,请问它的安全性乍样

jeongee 发表于 2011-9-2 15:20:34

我一直觉得你小子发帖子名称的时候可以再好好斟酌以下

a123123 发表于 2011-9-3 22:29:43

呵呵,jeongee好像认识楼上的哥们{:1_1:}
页: [1]
查看完整版本: ci官网的教程(插入新闻),呵呵