Question

This is my array that prints fields for each language

<?php foreach (Yii::app()->params['translatedLanguages'] as $l => $lang) :
                if($l === Yii::app()->params['defaultLanguage']) $suffix = '';
                else $suffix = '_'.$l;
                ?>
                <fieldset>
                    <legend><?php echo $lang; ?></legend>

                    <div class="row">
                        <?php echo $form->labelEx($model,'title'); ?>
                        <?php echo $form->textField($model,'title'.$suffix,array('size'=>60,'maxlength'=>255)); ?>
                        <?php echo $form->error($model,'title'.$suffix); ?>
                    </div>

                    <div class="row">
                        <?php echo $form->labelEx($model,'content'); ?>
                        <?php echo $form->textArea($model,'content'.$suffix); ?>
                        <?php echo $form->error($model,'content'.$suffix); ?>
                    </div>
                </fieldset>
            <?php endforeach; ?>

This is the yiistrap code for the tabs
http://www.getyiistrap.com/site/widgets#tabs

<?php $this->widget('bootstrap.widgets.TbTabs', array(
                'placement' => 'below',
                'tabs' => array(
                    array('label' => 'Home', 'content' => 'home test', 'active' => true),
                    array('label' => 'Profile', 'content' => 'profile test.'),
                ),
            )); ?>

How can I replace the content (e.g. home test) with the fields from my form? So in the end I have a tab for each language (like opencart)

Was it helpful?

Solution

This is the code for the tabs in my view

    <?php $tabs = array(); ?>
    <?php foreach (Yii::app()->params['translatedLanguages'] as $l => $lang) :
        if($l === Yii::app()->params['defaultLanguage']) $suffix = '';
        else $suffix = '_'.$l;
        ?>
        <?php $tabs[] = array('label' => $lang, 'view' => '_fields', 'viewData' => array('form' => $form, 'model' => $model, 'suffix' => $suffix)); ?>
    <?php endforeach; ?>

    <?php $this->widget('bootstrap.widgets.TbTabs', array(
        'tabs' => $tabs,
        'viewData' => array('form' => $form, 'model' => $model, 'suffix' => $suffix),
    )); ?>

And I added another view _fields.php

<?php echo $form->textFieldControlGroup($model,'title'.$suffix,array('span'=>5,'maxlength'=>128)); ?>
<?php echo $form->textAreaControlGroup($model,'content'.$suffix,array('rows'=>6,'span'=>8)); ?>

and I changed this in TbTabs.php ($tabOptions['viewData'])

protected function normalizeTabs($tabs)
{
    $controller = $this->getController();
    if (isset($controller)) {
        foreach ($tabs as &$tabOptions) {
            $items = TbArray::getValue('items', $tabOptions, array());
            if (!empty($items)) {
                $tabOptions['items'] = $this->normalizeTabs($items);
            } else {
                if (isset($tabOptions['view'])) {
                    $view = TbArray::popValue('view', $tabOptions);
                    if ($controller->getViewFile($view) !== false) {
                        $tabOptions['content'] = $controller->renderPartial($view, $tabOptions['viewData'], true);
                    }
                }
            }
        }
    }
    return $tabs;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top