|
控制器:
PHP复制代码
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:
PHP复制代码
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);
}
复制代码
相对我以前的把输入和验证捆一起的做法
这种形式好像挺清晰的,把验证和插入分开了,请问它的安全性乍样 |
|