/** * 添加/修改表单显示/处理函数 * * @access public * @return void */ public function _save_post() { $model = $this->input->get('model', TRUE); $this->session->set_userdata('model_type', 'model'); $this->session->set_userdata('model', $model); $this->settings->load('model/' . $model); $data['model'] = $this->settings->item('models'); $data['model'] = $data['model'][$model]; $id = $this->input->get('id'); $data['button_name'] = $id ? '编辑' : '添加'; $data['bread'] = make_bread(array('内容管理' => '', $data['model']['description'] => site_url('content/view?model=' . $data['model']['name']), $data['button_name'] => '')); if ($id) { $this->_check_permit('edit'); $data['content'] = $this->db->where('id', $id)->get($this->db->dbprefix('u_m_') . $model)->row_array(); $data['attachment'] = $this->db->where('model', $data['model']['id'])->where('content', $id)->where('from', 0)->get($this->db->dbprefix('attachments'))->result_array(); } else { $this->_check_permit('add'); $data['content'] = array(); } $this->load->library('form_validation'); foreach ($data['model']['fields'] as $v) { if ($v['rules'] != '') { $this->form_validation->set_rules($v['name'], $v['description'], str_replace(",", "|", $v['rules'])); } } $this->load->library('form'); $this->load->library('field_behavior'); if ($this->form_validation->run() == FALSE) { $thumb_preferences = json_decode($data['model']['thumb_preferences']); $data['thumb_default_size'] = ''; if ($thumb_preferences and $thumb_preferences->default != 'original') { $data['thumb_default_size'] = $thumb_preferences->default; } $this->_template('content_form', $data); } else { $modeldata = $data['model']; $data = array(); foreach ($modeldata['fields'] as $v) { if ($v['editable']) { $this->field_behavior->on_do_post($v, $data); } } $attachment = $this->input->post('uploadedfile', TRUE); if ($id) { $this->db->where('id', $id); $data['update_time'] = $this->session->_get_time(); $data['update_user'] = $this->_admin->uid; $this->plugin_manager->trigger('updating', $data, $id); $this->db->update($this->db->dbprefix('u_m_') . $model, $data); $this->plugin_manager->trigger('updated', $data, $id); if ($attachment != '0') { $this->db->set('model', $modeldata['id'])->set('from', 0)->set('content', $id)->where('aid in (' . $attachment . ')')->update($this->db->dbprefix('attachments')); } $this->_message('修改成功!', 'content/form', TRUE, '?model=' . $modeldata['name'] . '&id=' . $id); } else { $data['create_time'] = $data['update_time'] = $this->session->_get_time(); $data['create_user'] = $data['update_user'] = $this->_admin->uid; $this->plugin_manager->trigger('inserting', $data); $this->db->insert($this->db->dbprefix('u_m_') . $model, $data); $id = $this->db->insert_id(); $this->plugin_manager->trigger('inserted', $data, $id); if ($attachment != '0') { $this->db->set('model', $modeldata['id'])->set('from', 0)->set('content', $id)->where('aid in (' . $attachment . ')')->update($this->db->dbprefix('attachments')); } $this->_message('添加成功!', 'content/view', TRUE, '?model=' . $modeldata['name']); } } }
/** * 分类模型字段修改表单呈现/处理函数 * * @access public * @param int * @return void */ public function _edit_field_post($id = 0) { $data['field'] = $this->category_mdl->get_field_by_id($id); !$data['field'] and $this->_message('不存在的分类字段!', '', FALSE); $data['model'] = $this->category_mdl->get_category_model_by_id($data['field']->model); !$data['model'] and $this->_message('不存在的分类模型!', '', FALSE); $this->settings->load('fieldtypes'); if ($this->_validate_field_form($data['field']->model, $data['field']->name)) { $this->category_mdl->edit_category_field($data['model'], $data['field'], $this->_get_post_data()); update_cache('category', $data['model']->name); $this->_message('分类模型字段修改成功!', 'category/edit_field/' . $id, TRUE); } else { $data['bread'] = make_bread(array('模型管理' => '', '分类模型管理' => site_url('category/view'), $data['model']->description => site_url('category/fields/' . $data['model']->id), '编辑字段' => '')); $this->_template('fields_edit', $data); } }
/** * 添加/修改表单显示/处理函数 * * @access public * @return void */ public function _save_post() { $model = $this->input->get('model', TRUE); $this->session->set_userdata('model_type', 'category'); $this->session->set_userdata('model', $model); $this->settings->load('category/cate_' . $model); $data['model'] = $this->settings->item('cate_models'); $data['model'] = $data['model'][$model]; $id = $this->input->get('id'); if ($id) { $this->_check_permit('edit'); $data['content'] = $this->db->where('classid', $id)->get($this->db->dbprefix('u_c_') . $model)->row_array(); $data['attachment'] = $this->db->where('model', $data['model']['id'])->where('content', $id)->where('from', 1)->get($this->db->dbprefix('attachments'))->result_array(); $data['parentid'] = $data['content']['parentid']; $data['button_name'] = '编辑'; } else { $this->_check_permit('add'); $data['parentid'] = $this->input->get('u_c_level') ? $this->input->get('u_c_level') : 0; $data['content'] = array(); $data['button_name'] = '添加'; } if ($data['parentid'] > 0) { $current_level = $this->db->where('classid', $data['parentid'])->get($this->db->dbprefix('u_c_') . $model)->row()->level + 1; } else { $current_level = 1; } $data['path'] = $this->_find_path($current_level); $this->load->library('form_validation'); foreach ($data['model']['fields'] as $v) { if ($v['rules'] != '') { $this->form_validation->set_rules($v['name'], $v['description'], str_replace(",", "|", $v['rules'])); } } $this->load->library('form'); $this->load->library('field_behavior'); if ($this->form_validation->run() == FALSE) { $bread = array('分类管理' => '', $data['model']['description'] => site_url('category_content/view?model=' . $data['model']['name'])); if ($data['path']) { foreach ($data['path'] as $path) { $bread[translate_number_to_tradition($path)] = ''; } } $bread[$id ? '编辑' : '添加'] = ''; $data['bread'] = make_bread($bread); $thumb_preferences = json_decode($data['model']['thumb_preferences']); $data['thumb_default_size'] = ''; if ($thumb_preferences and $thumb_preferences->default != 'original') { $data['thumb_default_size'] = $thumb_preferences->default; } $this->_template('category_content_form', $data); } else { $modeldata = $data['model']; $data = array(); foreach ($modeldata['fields'] as $v) { if ($v['editable']) { $this->field_behavior->on_do_post($v, $data); } } $data['parentid'] = $this->input->post('parentid', TRUE); //获取path if ($data['parentid'] > 0) { //如果不是顶级分类,就读其path数据 $data['path'] = '{0}'; $data['level'] = 1; $parent_class = $this->db->where('classid', $data['parentid'])->get($this->db->dbprefix('u_c_') . $model)->row(); if ($parent_class) { $data['path'] = $parent_class->path; $data['level'] = $parent_class->level + 1; } else { $this->_message('不存在的顶级分类!', '', FALSE); } $data['path'] .= ',{' . $data['parentid'] . '}'; } else { $data['path'] = '{0}'; $data['level'] = 1; } $attachment = $this->input->post('uploadedfile', TRUE); if ($id) { $this->plugin_manager->trigger('updating', $data, $id); $this->db->where('classid', $id); $this->db->update($this->db->dbprefix('u_c_') . $model, $data); $this->plugin_manager->trigger('updated', $data, $id); if ($attachment != '0') { $this->db->set('model', $modeldata['id'])->set('from', 1)->set('content', $id)->where('aid in (' . $attachment . ')')->update($this->db->dbprefix('attachments')); } if ($modeldata['auto_update']) { update_cache('category', $model); } $this->_message('修改成功!', 'category_content/form', TRUE, '?model=' . $modeldata['name'] . '&id=' . $id); } else { $this->plugin_manager->trigger('inserting', $data); $this->db->insert($this->db->dbprefix('u_c_') . $model, $data); $id = $this->db->insert_id(); $this->plugin_manager->trigger('inserted', $data, $id); if ($attachment != '0') { $this->db->set('model', $modeldata['id'])->set('from', 1)->set('content', $id)->where('aid in (' . $attachment . ')')->update($this->db->dbprefix('attachments')); } if ($modeldata['auto_update']) { update_cache('category', $model); } $this->_message('添加成功!', 'category_content/view', true, '?model=' . $modeldata['name'] . '&u_c_level=' . $data['parentid']); } } }
// http://www.w3schools.com/php/php_functions.asp function make_cake() { // echo out a string echo "i made a cake"; } function make_bread() { // echo out a string return "i made some bread"; } // next we need to call the make_cake function // we do this by calling make_cake(); // or to call the return funciton we need to echo it out to see it echo make_bread(); // ==================================================================== // ARRAYS - just a list of items // http://www.w3schools.com/php/php_arrays.asp // an array of stings $animals = array("cats", "dogs", "rats", "bats", "hats?"); // an array of integers $numbers = array(5, 1, 8, 1, 5, 12); // getting single pieces of data from the array // array pockets start with 0 so the first pocket will be 0. // get pocket 1 from the animals array echo $animals[1]; // identify which pocket from the array you want to grab // get pocket 1 from the numbers array echo $numbers[1]; echo $numbers[0];