【发布时间】:2010-12-05 15:50:20
【问题描述】:
在 CodeIgniter 中,我有这样的模型和控制器,用于使用 AJAX 发表评论
型号:
class Items_model extends Model {
function add_comment($item_id, $user_id, $text, $type)
{
$data = array(
'item_id' => $item_id,
'user_id' => $user_id,
'text' => $text,
'type' => $type,
'created_at' => mktime()
);
$this->db->insert('comments', $data);
return $this->db->insert_id();
}
控制器:
class Items extends Controller {
function add_comment()
{
$this->load->helper('date');
$item_id = $this->input->post('item_id', TRUE);
$text = $this->input->post('comment_text', TRUE);
$type = $this->input->post('type', TRUE);
$user_id = $this->session->userdata('user_id'); // user id, must be logged in
$this->Items_model->add_comment($item_id, $user_id, $text, $type);
$response = array(
'message' => 'Thank you!'
);
echo json_encode($response);
}
我应该在控制器还是模型中控制表单中的数据:$item_id 和 $text 不为空,设置了 $user_id 并且用户已登录? 怎么做?
最好的,基里尔。
【问题讨论】:
标签: php codeigniter model controller weblogic