· 9 years ago · Jan 21, 2017, 11:32 PM
1CREATE TABLE IF NOT EXISTS `TheSims4PagesCategoriesRelations` (
2 `id` int(11) NOT NULL,
3 `postId` int(11) NOT NULL,
4 `catId` int(11) NOT NULL
5) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6
7ALTER TABLE `TheSims4PagesCategoriesRelations`
8 ADD CONSTRAINT `TheSims4PagesCategoriesRelations_ibfk_2` FOREIGN KEY (`catId`) REFERENCES `TheSims4PagesCategories` (`id`),
9 ADD CONSTRAINT `TheSims4PagesCategoriesRelations_ibfk_1` FOREIGN KEY (`postId`) REFERENCES `TheSims4Pages` (`id`);
10
11<?php
12
13namespace appmodelsTheSims4;
14
15use Yii;
16
17/**
18 * This is the model class for table "TheSims4Pages".
19 *
20 * @property integer $id
21 * @property string $pageName
22 * @property string $pageEditDate
23 * @property integer $isDraft
24 * @property integer $authorId
25 * @property string $pageText
26 *
27 * @property SiteUsers $author
28 * @property TheSims4PagesCategoriesRelations[] $theSims4PagesCategoriesRelations
29 */
30class TheSims4Pages extends yiidbActiveRecord {
31
32 /**
33 * @inheritdoc
34 */
35 public static function tableName() {
36 return 'TheSims4Pages';
37 }
38
39 /**
40 * @inheritdoc
41 */
42 public function rules() {
43 return [
44 [['pageName', 'authorId', 'pageText'], 'required'],
45 [['pageEditDate'], 'safe'],
46 [['isDraft', 'authorId'], 'integer'],
47 [['pageText'], 'string'],
48 [['pageName'], 'string', 'max' => 500],
49 [['authorId'], 'exist', 'skipOnError' => true, 'targetClass' => SiteUsers::className(), 'targetAttribute' => ['authorId' => 'id']],
50 ];
51 }
52
53 /**
54 * @inheritdoc
55 */
56 public function attributeLabels() {
57 return [
58 'id' => 'ID',
59 'pageName' => 'Page Name',
60 'pageEditDate' => 'Page Edit Date',
61 'isDraft' => 'Is Draft',
62 'authorId' => 'Author ID',
63 'pageText' => 'Page Text',
64 ];
65 }
66
67 /**
68 * @return yiidbActiveQuery
69 */
70 public function getAuthor() {
71 return $this->hasOne(SiteUsers::className(), ['id' => 'authorId']);
72 }
73
74 /**
75 * @return yiidbActiveQuery
76 */
77 public function getTheSims4PagesCategoriesRelations() {
78 return $this->hasMany(TheSims4PagesCategoriesRelations::className(), ['postId' => 'id']);
79 }
80
81}
82
83echo $form->field($model, 'categoryId')->dropDownList($listData);
84
85$model = new TheSims4Pages();