Skip to content

Commit f765037

Browse files
committed
Updated README.md
1 parent 2c44a75 commit f765037

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

README.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ The preferred way to install this extension is through [composer](http://getcomp
1313
Either run
1414

1515
```bash
16-
$ composer require creocoder/yii2-translateable:dev-master
16+
$ composer require creocoder/yii2-translateable
1717
```
1818

1919
or add
2020

2121
```
22-
"creocoder/yii2-translateable": "dev-master"
22+
"creocoder/yii2-translateable": "~1.0"
2323
```
2424

2525
to the `require` section of your `composer.json` file.
@@ -182,6 +182,64 @@ $result = $post->hasTranslation('ru-RU');
182182

183183
## Advanced usage
184184

185+
### Collecting tabular input
186+
187+
Example of controller actions
188+
189+
```php
190+
class PostController extends Controller
191+
{
192+
public function actionCreate()
193+
{
194+
$model = new Post();
195+
196+
foreach (Yii::$app->request->post('PostTranslation', []) as $language => $data) {
197+
foreach ($data as $attribute => $translation) {
198+
$model->translate($language)->$attribute = $translation;
199+
}
200+
}
201+
202+
//...
203+
}
204+
205+
public function actionUpdate($id)
206+
{
207+
$model = Post::find()->with('translations')->where(['id' => $id])->one();
208+
209+
if ($model === null) {
210+
throw new NotFoundHttpException('The requested page does not exist.');
211+
}
212+
213+
foreach (Yii::$app->request->post('PostTranslation', []) as $language => $data) {
214+
foreach ($data as $attribute => $translation) {
215+
$model->translate($language)->$attribute = $translation;
216+
}
217+
}
218+
219+
//...
220+
}
221+
}
222+
```
223+
224+
Example of view form
225+
226+
```php
227+
<?php
228+
use yii\helpers\Html;
229+
use yii\widgets\ActiveForm;
230+
231+
$form = ActiveForm::begin();
232+
233+
foreach (['en-US', 'de-DE', 'ru-RU'] as $language) {
234+
echo $form->field($model->translate($language), "[$language]title")->textInput();
235+
echo $form->field($model->translate($language), "[$language]body")->textarea();
236+
}
237+
238+
//...
239+
240+
ActiveForm::end();
241+
```
242+
185243
### Language specific translation attribute labels
186244

187245
Add the following to `PostTranslation` model

0 commit comments

Comments
 (0)