qa-ifish7/web/Application/Home/Model/InfoModel.class.php

46 lines
1.3 KiB
PHP

<?php
namespace Home\Model;
use Think\Model\RelationModel;
class InfoModel extends RelationModel{
protected $tableName,$_validate,$_link,$modelinfo,$modelid,$fieldarr;
public function __construct(){
//模型id
$catid=I("catid",0,"int");
if($catid){
$this->modelid=$GLOBALS['cat'][$catid]["modelid"];
}else{
$this->modelid=I("modelid",0,"int");
}
//模型信息
$modelinfo=$GLOBALS['model'][$this->modelid];
if(!$modelinfo){
return false;
}
$this->modelinfo=$modelinfo;
//
$this->_validate[]=array("catid","require","请选择分类",1);
//对应数据表
$this->tableName="cms_".$modelinfo['table_name'];
//关联模型
$this->_link = array(
//对应栏目表
"cat"=>array(
'mapping_type' => self::BELONGS_TO,
'foreign_key' => 'catid',
),
//【对应副表】
$this->tableName."_data"=>array(
'mapping_type' => self::HAS_ONE,
'foreign_key' => 'id',
),
);
//注意,这里父类析构函数一定要放到最下面,否则框架自带的方法不能使用
parent::__construct();
}
}