CREATE TABLE category (
id int(3) unsigned NOT NULL AUTO_INCREMENT,
parent_id int(3) unsigned NOT NULL DEFAULT '0',
slug char(30) NOT NULL,
position int(3) unsigned DEFAULT '999',
status smallint(1) unsigned DEFAULT '1',
created_at bigint(20) unsigned NOT NULL,
updated_at bigint(20) unsigned NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY slug (slug)
);
CREATE TABLE category_locale (
category_id int(3) unsigned NOT NULL,
language_code char(3) NOT NULL,
name char(45) NOT NULL,
status smallint(1) unsigned NOT NULL DEFAULT '1',
description text,
meta_title char(70) NOT NULL,
meta_description char(160) NOT NULL,
created_at bigint(20) unsigned NOT NULL,
updated_at bigint(20) unsigned NOT NULL,
PRIMARY KEY (category_id,language_code),
KEY FK_CL_language (language_code),
CONSTRAINT FK_CL_category FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FK_CL_language FOREIGN KEY (language_code) REFERENCES language (iso_code) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE language (
id int(3) unsigned NOT NULL AUTO_INCREMENT,
name char(32) NOT NULL,
iso_code char(3) NOT NULL,
language_code char(5) NOT NULL,
status smallint(1) unsigned NOT NULL DEFAULT '1',
is_default smallint(1) unsigned NOT NULL DEFAULT '0',
created_at bigint(20) unsigned NOT NULL,
updated_at bigint(20) unsigned NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY iso_code (iso_code)
);
Data not saved in language table.
CREATE TABLE
category
(id
int(3) unsigned NOT NULL AUTO_INCREMENT,parent_id
int(3) unsigned NOT NULL DEFAULT '0',slug
char(30) NOT NULL,position
int(3) unsigned DEFAULT '999',status
smallint(1) unsigned DEFAULT '1',created_at
bigint(20) unsigned NOT NULL,updated_at
bigint(20) unsigned NOT NULL, PRIMARY KEY (id
), UNIQUE KEYslug
(slug
) );CREATE TABLE
category_locale
(category_id
int(3) unsigned NOT NULL,language_code
char(3) NOT NULL,name
char(45) NOT NULL,status
smallint(1) unsigned NOT NULL DEFAULT '1',description
text,meta_title
char(70) NOT NULL,meta_description
char(160) NOT NULL,created_at
bigint(20) unsigned NOT NULL,updated_at
bigint(20) unsigned NOT NULL, PRIMARY KEY (category_id
,language_code
), KEYFK_CL_language
(language_code
), CONSTRAINTFK_CL_category
FOREIGN KEY (category_id
) REFERENCEScategory
(id
) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINTFK_CL_language
FOREIGN KEY (language_code
) REFERENCESlanguage
(iso_code
) ON DELETE CASCADE ON UPDATE CASCADE );CREATE TABLE
language
(id
int(3) unsigned NOT NULL AUTO_INCREMENT,name
char(32) NOT NULL,iso_code
char(3) NOT NULL,language_code
char(5) NOT NULL,status
smallint(1) unsigned NOT NULL DEFAULT '1',is_default
smallint(1) unsigned NOT NULL DEFAULT '0',created_at
bigint(20) unsigned NOT NULL,updated_at
bigint(20) unsigned NOT NULL, PRIMARY KEY (id
), UNIQUE KEYiso_code
(iso_code
) );'ml' => [ 'class' => MultilingualBehavior::className(), 'languages' => [ 'en-IN' => 'English' ], 'langClassName' => CategoryLocale::className(), 'langForeignKey' => 'category_id', 'tableName' => "{{%category_locale}}", 'languageField' => 'language_code', 'requireTranslations' => true, 'attributes' => [ 'name', 'description', 'meta_title', 'meta_description' ] ]
Below is my form :-
Below is my controller code :-1:
public function actionUpdate( $id ) { $model = $this->findModel( $id, true ); print_r($model->save()); if ( $model->load( Yii::$app->request->post() ) && $model->save() ) { echo "here"; return $this->redirect( [ 'view', 'id' => $model->id ] ); } else { return $this->render( 'update', [ 'model' => $model, ] ); } }
protected function findModel( $id, $ml = false ) { if ($ml) { $model = Category::find()->where([ 'id' => $id ])->multilingual()->one(); } else { $model = Category::findOne( $id ); } if ( $model !== null ) { return $model; } else { throw new NotFoundHttpException( 'The requested page does not exist.' ); } }