Модель
Код: Выделить всё
class Menu extends \yii\db\ActiveRecord {
/**
* @inheritdoc
*/
public static function tableName() {
return 'menu';
}
/**
* @inheritdoc
*/
public function rules() {
return [
[['parent_id', 'name', 'display_url'], 'required'],
[['parent_id', 'items_order', 'can_be_deleted', 'is_hidden'], 'integer'],
[['name', 'inner_url', 'display_url'], 'string', 'max' => 200],
[['name', 'inner_url', 'display_url'], 'trim'],
[['display_url'], 'unique'],
];
}
Код: Выделить всё
public function actionCreate() {
$model = new Menu();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Код: Выделить всё
DROP TABLE IF EXISTS `menu`;
CREATE TABLE `menu` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int(10) unsigned NOT NULL,
`items_order` int(10) unsigned NOT NULL DEFAULT '0',
`name` varchar(200) NOT NULL,
`inner_url` varchar(200) NOT NULL DEFAULT 'site/custom',
`display_url` varchar(200) NOT NULL,
`can_be_deleted` tinyint(4) NOT NULL DEFAULT '1',
`is_hidden` tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `url` (`display_url`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Код: Выделить всё
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'items_order' cannot be null