Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language table empty when creating model #58

Open
vikashgirnar opened this issue Dec 8, 2016 · 0 comments
Open

Language table empty when creating model #58

vikashgirnar opened this issue Dec 8, 2016 · 0 comments

Comments

@vikashgirnar
Copy link

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 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)
);

'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 :-

<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'parent_id')->textInput() ?>

<?= $form->field($model, 'position')->textInput() ?>

<?= $form->field($model, 'name_en')->textInput() ?>

<?= $form->field($model, 'slug')->textInput() ?>

<?= $form->field($model, 'description_en')->textInput() ?>

<?= $form->field($model, 'meta_title_en')->textInput() ?>

<?= $form->field($model, 'meta_description_en')->textInput() ?>

<?= $form->field($model, 'status')->checkbox() ?>


<div class="form-group">
    <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>

Below is my controller code 👎

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.' );
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant