Jump to content
Sign in to follow this  
nash

[Решено?..] Сохранение параметров модуля в таблице setting

Recommended Posts

Добрый день! Пробую написать простой модуль. Возникла проблема - не могу сохранить в таблице параметры модуля (из полей таблицы). Расположение, сортировка модуля и т.д. сохраняется нормально, а данные из формы не пишутся в таблицу setting

 

код под спойлером

 

<?php echo $header; ?>
<div id="content">
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
<?php } ?>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<div class="box">
<div class="heading">
<h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
<div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a></div>
</div>
<div class="content">
    <div id="tabs" class="htabs">
        <a href="#tab-general">Основные</a>
        <a href="#tab-razmeschenie">Размещение</a>
    </div>

<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
<div id="tab-razmeschenie" class="tab-content">
     <table id="module" class="list">
<thead>
<tr>
<td class="left"><?php echo $entry_layout; ?></td>
<td class="left"><?php echo $entry_position; ?></td>
<td class="left"><?php echo $entry_status; ?></td>
<td class="right"><?php echo $entry_sort_order; ?></td>
<td></td>
</tr>
</thead>
<?php $module_row = 0; ?>
<?php foreach ($modules as $module) { ?>
<tbody id="module-row<?php echo $module_row; ?>">
<tr>
<td class="left"><select name="calc_module[<?php echo $module_row; ?>][layout_id]">
<?php foreach ($layouts as $layout) { ?>
<?php if ($layout['layout_id'] == $module['layout_id']) { ?>
<option value="<?php echo $layout['layout_id']; ?>" selected="selected"><?php echo $layout['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>
<?php } ?>
<?php } ?>
</select></td>
<td class="left"><select name="calc_module[<?php echo $module_row; ?>][position]">
<?php if ($module['position'] == 'content_topl') { ?>
                                        <option value="content_topl" selected="selected">Для каталога-калькулятора</option>
                                        <?php } else { ?>
                                        <option value="content_topl">Для каталога-калькулятора</option>
                                        <?php } ?>

<?php if ($module['position'] == 'content_top') { ?>
<option value="content_top" selected="selected"><?php echo $text_content_top; ?></option>
<?php } else { ?>
<option value="content_top"><?php echo $text_content_top; ?></option>
<?php } ?>
<?php if ($module['position'] == 'content_bottom') { ?>
<option value="content_bottom" selected="selected"><?php echo $text_content_bottom; ?></option>
<?php } else { ?>
<option value="content_bottom"><?php echo $text_content_bottom; ?></option>
<?php } ?>
<?php if ($module['position'] == 'column_left') { ?>
<option value="column_left" selected="selected"><?php echo $text_column_left; ?></option>
<?php } else { ?>
<option value="column_left"><?php echo $text_column_left; ?></option>
<?php } ?>
<?php if ($module['position'] == 'column_right') { ?>
<option value="column_right" selected="selected"><?php echo $text_column_right; ?></option>
<?php } else { ?>
<option value="column_right"><?php echo $text_column_right; ?></option>
<?php } ?>
</select></td>
<td class="left"><select name="calc_module[<?php echo $module_row; ?>][status]">
<?php if ($module['status']) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_enabled; ?></option>
<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
<?php } ?>
</select></td>
<td class="right"><input type="text" name="calc_module[<?php echo $module_row; ?>][sort_order]" value="<?php echo $module['sort_order']; ?>" size="3" /></td>
<td class="left"><a onclick="$('#module-row<?php echo $module_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
</tr>
</tbody>
<?php $module_row++; ?>
<?php } ?>
<tfoot>
<tr>
<td colspan="4"></td>
<td class="left"><a onclick="addModule();" class="button"><?php echo $button_add_module; ?></a></td>
</tr>
</tfoot>
</table>
        </div>
</form>
<div id="tab-general">
    
     <table class="form">
<tr>
<td><span class="required">*</span> Коэфф высоты до 3х метров</td>
<td><input type="text" name="do_3x_metrov" maxlength="255" size="100" value="<?php $do_3x_metrov; ?>" /></td>
</tr>
<tr>
<td><span class="required">*</span> Коэфф высоты свыше 3х метров</td>
<td><input type="text" name="ot_3x_metrov" maxlength="255" size="100" value="" /></td>
</tr>
<tr>
<td><span class="required">*</span> Коэфф солнечной стороны</td>
<td><input type="text" name="k_solnechnaya" maxlength="255" size="100" value="" /></td>
</tr>
             <tr><td colspan="2"><h2>Диапазон рассчитанной мощности</h2></td><td></td></tr>
<tr>
<td><span class="required">*</span> От (в процентах)</td>
<td><input type="text" name="diapazon_ot" maxlength="255" size="100" value="" /></td>
</tr>
<tr>
<td><span class="required">*</span> До (в процентах)</td>
<td><input type="text" name="diapazon_do" maxlength="255" size="100" value="" /></td>
</tr>
</table>
    
    </div>
    </form>
</div>
</div>
</div>
<script type="text/javascript"><!--
var module_row = <?php echo $module_row; ?>;

function addModule() {    
    html = '<tbody id="module-row' + module_row + '">';
    html += ' <tr>';
    html += ' <td class="left"><select name="calc_module[' + module_row + '][layout_id]">';
    <?php foreach ($layouts as $layout) { ?>
    html += ' <option value="<?php echo $layout['layout_id']; ?>"><?php echo addslashes($layout['name']); ?></option>';
    <?php } ?>
    html += ' </select></td>';
    html += ' <td class="left"><select name="calc_module[' + module_row + '][position]">';
    html += '     <option value="content_topl">Для каталога-калькулятора</option>';
    html += ' <option value="content_top"><?php echo $text_content_top; ?></option>';
    html += ' <option value="content_bottom"><?php echo $text_content_bottom; ?></option>';
    html += ' <option value="column_left"><?php echo $text_column_left; ?></option>';
    html += ' <option value="column_right"><?php echo $text_column_right; ?></option>';
    html += ' </select></td>';
    html += ' <td class="left"><select name="calc_module[' + module_row + '][status]">';
html += ' <option value="1" selected="selected"><?php echo $text_enabled; ?></option>';
html += ' <option value="0"><?php echo $text_disabled; ?></option>';
html += ' </select></td>';
    html += ' <td class="right"><input type="text" name="calc_module[' + module_row + '][sort_order]" value="" size="3" /></td>';
    html += ' <td class="left"><a onclick="$(\'#module-row' + module_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
    html += ' </tr>';
    html += '</tbody>';

    $('#module tfoot').before(html);

    module_row++;
}
//--></script>
<script type="text/javascript"><!--
$('#tabs a').tabs();
//--></script>
<?php echo $footer; ?>

контроллер: 

<?php
class ControllerModuleCalc extends Controller {
    private $error = array();

    public function index() {
        $this->load->language('module/calc');
        $this->document->setTitle($this->language->get('heading_title'));
        $this->load->model('setting/setting');

        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            $this->model_setting_setting->editSetting('calc', $this->request->post);        

            $this->session->data['success'] = $this->language->get('text_success');

            $this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
        }

        $this->data['heading_title'] = $this->language->get('heading_title');

        $this->data['text_enabled'] = $this->language->get('text_enabled');
        $this->data['text_disabled'] = $this->language->get('text_disabled');
        $this->data['text_content_top'] = $this->language->get('text_content_top');
        $this->data['text_content_bottom'] = $this->language->get('text_content_bottom');        
        $this->data['text_column_left'] = $this->language->get('text_column_left');
        $this->data['text_column_right'] = $this->language->get('text_column_right');

        $this->data['entry_layout'] = $this->language->get('entry_layout');
        $this->data['entry_position'] = $this->language->get('entry_position');
        $this->data['entry_status'] = $this->language->get('entry_status');
        $this->data['entry_sort_order'] = $this->language->get('entry_sort_order');

        $this->data['button_save'] = $this->language->get('button_save');
        $this->data['button_cancel'] = $this->language->get('button_cancel');
        $this->data['button_add_module'] = $this->language->get('button_add_module');
        $this->data['button_remove'] = $this->language->get('button_remove');

        if (isset($this->error['warning'])) {
            $this->data['error_warning'] = $this->error['warning'];
        } else {
            $this->data['error_warning'] = '';
        }

        $this->data['breadcrumbs'] = array();

        $this->data['breadcrumbs'][] = array(
        'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
        'separator' => false
        );

        $this->data['breadcrumbs'][] = array(
        'text' => $this->language->get('text_module'),
            'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
        'separator' => ' :: '
        );

        $this->data['breadcrumbs'][] = array(
        'text' => $this->language->get('heading_title'),
            'href' => $this->url->link('module/calc', 'token=' . $this->session->data['token'], 'SSL'),
        'separator' => ' :: '
        );

        $this->data['action'] = $this->url->link('module/calc', 'token=' . $this->session->data['token'], 'SSL');

        $this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');

        $this->data['modules'] = array();

        if (isset($this->request->post['calc_module'])) {
            $this->data['modules'] = $this->request->post['calc_module'];
        } elseif ($this->config->get('calc_module')) {
            $this->data['modules'] = $this->config->get('calc_module');
        }                
        
        if (isset($this->request->post['do_3x_metrov'])) {
            $this->data['do_3x_metrov'] = $this->request->post['do_3x_metrov'];
        } elseif ($this->config->get('do_3x_metrov')) {
            $this->data['do_3x_metrov'] = $this->config->get('do_3x_metrov');
        }
        
        $this->load->model('design/layout');

        $this->data['layouts'] = $this->model_design_layout->getLayouts();

        $this->template = 'module/calc.tpl';
        $this->children = array(
            'common/header',
            'common/footer'
        );                
        $this->response->setOutput($this->render());
    }

    private function validate() {
        if (!$this->user->hasPermission('modify', 'module/calc')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }

        if (!$this->error) {
            return true;
        } else {
            return false;
        }    
    }
}
?> 

 

скрин

AD7h46lT.png

 

В чем ошибка, помогите, пожалуйста!

Share this post


Link to post
Share on other sites

Код не смотрел, но в 90% случаев, в отсутствии префикса модуля в имени настройки 

Share this post


Link to post
Share on other sites

Код не смотрел, но в 90% случаев, в отсутствии префикса модуля в имени настройки 

прописал префикс, все равно что-то не работает

Share this post


Link to post
Share on other sites

Размещение  - должно сохраняться

 

А все остальное - увы..

 

раз

        if (isset($this->request->post['do_3x_metrov'])) {
            $this->data['do_3x_metrov'] = $this->request->post['do_3x_metrov'];
        } elseif ($this->config->get('do_3x_metrov')) {
            $this->data['do_3x_metrov'] = $this->config->get('do_3x_metrov');
        }

а тут..

   <tr>
    <td><span class="required">*</span> Коэфф высоты до 3х метров</td>
    <td><input type="text" name="do_3x_metrov" maxlength="255" size="100" value="<?php $do_3x_metrov; ?>" /></td>
    </tr>
    <tr>
    <td><span class="required">*</span> Коэфф высоты свыше 3х метров</td>
    <td><input type="text" name="ot_3x_metrov" maxlength="255" size="100" value="" /></td>
    </tr>

Т.е. Вы сохраняете только один параметр

Хотите сохранить все

сделайте, например

 

name="calc_paramеtr[do_3x_metrov]" и тд

 

тем самым вы уменьшите записей для модуля.

 

 

При записи  - выводите принятый массив

$this->log->write(print_r($this->request->post,true))

Share this post


Link to post
Share on other sites

да, размещение сохраняется. А в "основных" я тестировал один параметр.

Share this post


Link to post
Share on other sites

:D

а зачем ты форму закрыл "посреди формы"?

</form>
<div id="tab-general">

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.