/** * 文档新增页面初始化 * @author huajie <*****@*****.**> */ public function add() { //获取左边菜单 $cate_id = I('get.cate_id', 0); $model_id = 4; empty($cate_id) && $this->error('参数不能为空!'); empty($model_id) && $this->error('参数不能为空!'); //检查该分类是否允许发布 $allow_publish = D('ShopProduct')->checkCategory($cate_id); !$allow_publish && $this->error('该分类不允许发布内容!'); /* 获取要编辑的扩展模型模板 */ $model = get_model($model_id); //处理结果 $info['pid'] = $_GET['pid'] ? $_GET['pid'] : 0; $info['model_id'] = $model_id; $info['cid'] = $cate_id; if ($info['pid']) { // 获取上级文档 $article = M('ShopProduct')->field('id,title,type')->find($info['pid']); $this->assign('article', $article); } //获取表单字段排序 $fields = get_model_attribute($model['id']); $this->assign('info', $info); $this->assign('fields', $fields); $this->assign('type_list', get_type_bycate($cate_id)); $this->assign('model', $model); $this->meta_title = '新增' . $model['title']; $this->display(); }
function get_province() { $ci = get_model(); $data['district'] = $ci->province->get_district(); $data['amphur'] = $ci->province->get_amphur(); $data['province'] = $ci->province->get_province(); return $data; }
public function __construct() { $model_id = I('model_id'); $this->m_name = $model_id; if (is_numeric($model_id)) { $this->m_info = get_model($model_id); } else { $this->m_info = M('Model')->where("`table`='{$model_id}'")->find(); } parent::__construct(); }
function get_selected($id) { $ci = get_model(); $data['id'] = $id; $data['address'] = $ci->input->post('address_com'); $date = $ci->input->post('date'); $date = date_eng_to_data($date); $data['date'] = date_to_pdf($date); $data['name_manager'] = $ci->input->post('name_manager'); $data['name_manager2'] = $ci->input->post('name_manager2'); $data['witness'] = $ci->input->post('witness'); $data['witness2'] = $ci->input->post('witness2'); $data['position_manager'] = $ci->input->post('position_manager'); $data['faction'] = $ci->input->post('faction'); return $data; }
/** * Public constructor * * @param array $dataray Set of data used by object * @return System\Model\Attr */ public function __construct(array $dataray = array()) { $model = get_model($this); $model::check_model(); $this->update_attrs($dataray); if (static::USE_INITIAL_DATA && any($dataray)) { $this->data_initial = $this->data; } if (isset($model::$attrs['pass'])) { foreach ($model::$attrs['pass'] as $attr) { $old_attr = $attr . '_old'; $this->{$old_attr} = $this->{$attr}; } } if (method_exists($this, 'construct')) { $this->construct($dataray); } unset($this->opts['changed']); }
function fulladdress_company() { $ci = get_model(); $data['company'] = $ci->company->get_company(); $blank = " "; foreach ($data['company'] as $get) { $address = $get->address; $amphur = $get->amphur; $locality = $get->locality; $province = $get->province; $postcode = $get->postcode; $tel = $get->tel; $fulladdress['fulladdress'] = $address . $blank . $amphur . $blank . $locality . $blank . $province . $blank . $postcode . $blank . "โทรศัพท์ " . $tel; if ($get->fax != "") { $fax = $get->fax; $fulladdress['fulladdress'] = $fulladdress['fulladdress'] . $blank . "แฟกซ์ " . $fax; } $id['id'] = $get->id; $ci->db->where('id', $id['id'])->update('company', $fulladdress); } }
function fulladdress_employee($id) { $ci = get_model(); $data['employee'] = $ci->db->where('id', $id)->get('employee')->result(); $blank = " "; foreach ($data['employee'] as $get) { $address = $get->address; $amphur = $get->amphur; $locality = $get->locality; $province = $get->province; $postcode = $get->postcode; $tel = $get->tel; $fulladdress['fulladdress'] = $address . $blank . $amphur . $blank . $locality . $blank . $province . $blank . $postcode . $blank . "โทรศัพท์ " . $tel; if ($get->fax != "") { $fax = $get->fax; $fulladdress['fulladdress'] = $fulladdress['fulladdress'] . $blank . "แฟกซ์ " . $fax; } $ci->db->where('id', $id)->update('employee', $fulladdress); return $fulladdress['fulladdress']; } }
/** * 合并分类 * @author huajie <*****@*****.**> */ public function merge() { $to = I('post.to'); $from = I('post.from'); $Model = M('Catalog'); //检查分类绑定的模型 $from_models = explode(',', $Model->getFieldById($from, 'model')); $to_models = explode(',', $Model->getFieldById($to, 'model')); foreach ($from_models as $value) { if (!in_array($value, $to_models)) { $this->error('请给目标分类绑定' . get_model($value, 'title') . '模型'); } } //检查分类选择的文档类型 $from_types = explode(',', $Model->getFieldById($from, 'type')); $to_types = explode(',', $Model->getFieldById($to, 'type')); foreach ($from_types as $value) { if (!in_array($value, $to_types)) { $types = C('DOCUMENT_MODEL_TYPE'); $this->error('请给目标分类绑定文档类型:' . $types[$value]); } } //合并产品 $res = M('ShopProduct')->where(array('cid' => $from))->setField('cid', $to); if ($res) { //删除被合并的分类 $Model->delete($from); $this->success('合并分类成功!', U('index')); } else { $this->error('合并分类失败!'); } }
/** * 获取扩展模型对象 * @param integer $model 模型编号 * @return object 模型对象 */ private function logic($model) { return D(get_model($model, 'name'), 'Logic'); }
/** *取表单模型数据数组 *@param $model_id 模型id或标识 *@param $field 模型的字段值 *@param $attr 字段的属性值 如 title note name field extra type......等 常用的有extra文章属性标记返回的是一个数组 * **/ function get_model_attr($model_id = null, $field = null, $attr = null) { $skey = $model_id . '_' . $field . '_' . $attr; $relist = F('_modelform/' . $skey); if (empty($relist) || APP_DEBUG) { $list = array(); if (empty($model_id)) { return null; } $data = get_model($model_id); if (empty($data)) { return null; } $model_id = $data['model_id']; $list = M('ModelAttr')->where("model_id={$model_id}")->order('sort asc')->select(); $refield = null; foreach ($list as $key => $val) { if (!empty($val['extra'])) { $redata = parse_string_function($val['extra']); if ($redata === false) { //如果是数组格式就转化成数组 $list[$key]['extra'] = extra_to_array($val['extra']); } else { $list[$key]['extra'] = $redata; } } if (!empty($field) and $val['field'] === $field) { if (empty($attr)) { $relist = $list[$key]; F('_modelform/' . $skey, $relist); return $list[$key]; } else { $relist = $list[$key][$attr]; F('_modelform/' . $skey, $relist); return $list[$key][$attr]; } } } $relist = $list; F('_modelform/' . $skey, $list); } return $relist; }
return $t[0] . $t[1]; } ?> <p> <ul id="new-cars"> <?php foreach ($models as $model) { ?> <li class="car"> <a href="/buy-new/<?php print trim(strtolower($make->CMan_Name)); ?> /<?php print trim(get_model($model->CRan_Name)); ?> " class="<?php print get_model($model->CRan_Name); ?> "> <?php print ucspecial($model->CRan_Name); ?> </a> </li> <?php } ?> </ul> </p>
public function show($id = 0, $p = 1) { /* 标识正确性检测 */ if (!($id && is_numeric($id))) { $this->error('文档ID错误!'); } /* 页码检测 */ $p = intval($p); $p = empty($p) ? 1 : $p; /* 获取详细信息 */ $Document = D('Document'); $info = $Document->show($id); if (!$info) { $this->error($Document->getError()); } /* 分类信息 */ $category = $this->category($info['category_id']); /* 获取模板 */ if (!empty($info['template'])) { //已定制模板 $tmpl = $info['template']; } elseif (!empty($category['template_detail'])) { //分类已定制模板 $tmpl = $category['template_detail']; } elseif (strcmp($category['model'], '2') !== 0) { //使用默认模板 $tmpl = 'Article/show_' . get_model($category['model'], 'name'); } else { $tmpl = 'Article/show'; } /* 更新浏览数 */ $map = array('id' => $id); $Document->where($map)->setInc('view'); /* 模板赋值并渲染模板 */ $this->assign('category', $category); $this->assign('info', $info); $this->assign('page', $p); //页码 $this->display($tmpl); }
function get_information_pdf4($data) { $ci = get_model(); $data['fulladdress_employeee'] = fulladdress_employee($data['id']); $get = apprentice($data['id']); $data['apprentice'] = $get['end']; $data['end'] = $get['end2']; $data['sum_salary'] = $data['employee'][0]->salary + $data['employee'][0]->raisesalary; $data['thai_sum_salary'] = number_to_thai($data['sum_salary']); $data['thai_raisesalary'] = number_to_thai($data['employee'][0]->raisesalary); generate_pdf4($data); }
/** * Assign and save relation by IDs * * @param string $rel_name Name of relation * @param array $ids_new List of new IDs - others will be deleted * @return $this */ public function validate_relation_hasmany($attr) { if (isset($this->relations[$attr])) { $model = get_model($this); $def = $this::get_attr($attr); $value = $this->relations[$attr]; $corrected = array(); foreach ($this->relations[$attr] as $val) { if (gettype($val) == 'integer') { $m = $def['model']; $obj = $m::find($val); if ($obj) { $corrected[] = $m::find($val); } else { throw new \System\Error\Model(sprintf("Cannot assign object '%s#%s' to instance of '%s'. Object does not exist.", $def['model'], $val, $model)); } } } return $corrected; } else { return array(); } }
function test_fangomodel_isnew() { $model = get_model(); $model->pk = 'id'; assert($model->isNew(array('id' => 1)) == false); assert($model->isNew(array('id' => 100)) == true); }