Jump to content
Sign in to follow this  
ArtemPitov

[Решено] Контроллер модуля (вопрос по PHP)

Recommended Posts

Доброго времени суток ! 

Пишу простенький модуль по выводу произвольных блоков, по аналогу банера,  возник такой вопрос по контроллеру админки

 

1. данные передаем   админки в таком виде

["cust_block"]=>
  array(1) {
    [0]=>
    array(5) {
      ["image"]=>""
      ["'title'"]=>
      array(2) {
        [1]=>
        string(5) "title"
        [2]=>
        string(5) "title"
      }
      ["'description'"]=>
      array(2) {
        [1]=>
        string(4) "desk"
        [2]=>
        string(5) "desk"
      }
      ["'link'"]=>
      array(2) {
        [1]=>
        string(4) "link"
        [2]=>
        string(4) "link"
      }
      ["sort_order"]=>
      string(4) "sort"
    }

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

if (isset($this->request->post['cust_block'])) {
$cust_block = $this->request->post['cust_block'];
} elseif (isset($this->request->get['cust_block'])) {
$cust_block = ??
} else {
$cust_block = array();
}

возник вопрос, вот в чем, если одна или несколько форм заполнены то выполняется условия в банере вот так

$$banner_images = $this->model_design_banner->getBannerImages($this->request->get['banner_id']); 

а у модуля,  выходит получаем так,  и это только для одного пункта

} elseif (!empty($module_info)) {
$data[' '] = $module_info[' ']; }

Сам вопрос:  Как правильно написать условия возврата данных в форму ?  спасибо !

 

 

Edited by ArtenPitov

Share this post


Link to post
Share on other sites

Перефразирую вопрос, как получить массив из settings модуля ? 

Share this post


Link to post
Share on other sites

еще даже декабрь не начался, а ты опять какую-то пургу нагоняешь :ugeek:

мешаешь мух

cust_block
котлеты

$banner_images = $this->model_design_banner->getBannerImages($this->request->get['banner_id']);
и вон-тот-тюбик-то-ли-с-кетчупом-то-ли-с-вазелином.

давай по новой.

и со скриншотом.

Share this post


Link to post
Share on other sites

После долгого сидения и познавания нового в php, я изъясняюсь как Кличко), так что извиняюсь за выше написанное )  

 

1. Вот сама форма которой передаю данные 

<div class="panel-body">
        <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="cust_block" class="form-horizontal">
          
          <div class="row form-group">
            <div class="col-sm-6">
              <label class="col-sm-2 control-label" for="input-name"><?php echo $entry_name; ?></label>
              <div class="col-sm-10">
                <input type="text" name="name" value="<?php echo $name; ?>" placeholder="<?php echo $entry_name; ?>" id="input-name" class="form-control" />
                <?php if ($error_name) { ?>
                <div class="text-danger"><?php echo $error_name; ?></div>
                <?php } ?>
              </div>
            </div>

            <div class="col-sm-6">
              <label class="col-sm-2 control-label" for="input-status"><?php echo $entry_status; ?></label>
              <div class="col-sm-10">
                <select name="status" id="input-status" class="form-control">
                  <?php if ($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>
              </div>
            </div>
          </div>

          <div class="col-sm-12">
            <table id="items" class="table table-striped table-hover">
            
            <tbody>
              <?php $number_row = 0; ?>
              <?php foreach ($cust_block as $block) { ?>  
              <tr id="item-row<?php echo $number_row ?>">
                
                
                <td>
                  <a href="" id="thumb-image<?php echo $number_row; ?>" data-toggle="image" class="img-thumbnail">
                    <img src="<?php echo $cust_block['thumb']; ?>" alt="" title="" data-placeholder="<?php echo $placeholder; ?>" /></a>
                    <input type="hidden" name="cust_block[<?php echo $number_row; ?>][image]" 
                    value="<?php echo $cust_block['image']; ?>" id="input-image<?php echo $number_row; ?>" />
                </td>

                
                <td>
                  <?php foreach ($languages as $language) { ?>
                  <div class="input-group pull-left">
                    <span class="input-group-addon">
                     <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> 
                    </span> 
                    <input type="text" placeholder="<?php echo $entry_title; ?>" class="form-control"
                    name="cust_block[<?php echo $number_row; ?>]['title'][<?php echo $language['language_id']; ?>]"
                    value="<?php echo isset($cust_block['number_row']['title'][$language['language_id']]) ? $cust_block['number_row']['title'][$language['language_id']] : ''; ?>" > 
                  </div>
                  <?php } ?> 
                </td>
                
                
                <td>
                  <?php foreach ($languages as $language) { ?>
                  <div class="input-group pull-left">
                    <span class="input-group-addon">
                     <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> 
                    </span> 
                    <input type="text" placeholder="<?php echo $entry_description; ?>" class="form-control"
                    name="cust_block[<?php echo $number_row; ?>]['description'][<?php echo $language['language_id']; ?>]"
                    value="<?php echo isset($cust_block['number_row']['description'][$language['language_id']]) ? $description_box['number_row']['description'][$language['language_id']] : ''; ?>" > 
                  </div>
                  <?php } ?>   
                </td>
                
                
                <td>
                  <?php foreach ($languages as $language) { ?>
                  <div class="input-group pull-left">
                    <span class="input-group-addon">
                     <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> 
                    </span> 
                    <input type="text" placeholder="<?php echo $entry_link; ?>" class="form-control"
                    name="cust_block[<?php echo $number_row; ?>]['link'][<?php echo $language['language_id']; ?>]"
                    value="<?php echo isset($cust_block['number_row']['link'][$language['language_id']]) ? $cust_block['number_row']['link'][$language['language_id']] : ''; ?>" > 
                  </div>
                  <?php } ?>  
                </td>
              
               
                <td style="width:30%">
                  <input type="text" name="cust_block[<?php echo $number_row; ?>][sort_order]" value="<?php echo $cust_block['sort_order']; ?>" placeholder="<?php echo $entry_sort_order; ?>" class="form-control" />
                </td>

                
                <td>
                  <button type="button" onclick="$('#item-row<?php echo $number_row; ?>, .tooltip').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-trash"></i></button>
                </td>

              </tr>
              <?php $number_row++; ?>
              <?php } ?>
            </tbody>
            
              
            <tfoot>
              <tr>
                <td colspan="5"></td>
                <td class="text-right">
                  <button type="button" onclick="addBox();" data-toggle="tooltip" title="<?php echo $button_box_add; ?>" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button>
                </td>
              </tr>
            </tfoot>  
              
          
            </table>  
          </div>

        </form>
      </div>
2. вот пхп

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

	public function index() {
		$this->load->language('module/info_line');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('extension/module');

		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
			if (!isset($this->request->get['module_id'])) {
				$this->model_extension_module->addModule('info_line', $this->request->post);
			} else {
				$this->model_extension_module->editModule($this->request->get['module_id'], $this->request->post);
			}

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

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

		$strings = array(
			'heading_title',
			'text_edit',
			'text_enabled',
			'text_disabled',
			'text_image',

			'entry_name',
			'entry_title',
			'entry_description',
			'entry_status',
			'entry_link',
			'entry_sort_order',

			'button_save',
			'button_cancel',
			'button_remove',
			'button_box_add'
		);

		foreach ($strings as $srting){
			$data[$srting] = $this->language->get($srting);
		}

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

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

		$data['breadcrumbs'] = array();

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

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

		if (!isset($this->request->get['module_id'])) {
			$data['breadcrumbs'][] = array(
				'text' => $this->language->get('heading_title'),
				'href' => $this->url->link('module/info_line', 'token=' . $this->session->data['token'], 'SSL')
			);
		} else {
			$data['breadcrumbs'][] = array(
				'text' => $this->language->get('heading_title'),
				'href' => $this->url->link('module/info_line', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], 'SSL')
			);
		}

		if (!isset($this->request->get['module_id'])) {
			$data['action'] = $this->url->link('module/info_line', 'token=' . $this->session->data['token'], 'SSL');
		} else {
			$data['action'] = $this->url->link('module/info_line', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], 'SSL');
		}

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

		if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
			$module_info = $this->model_extension_module->getModule($this->request->get['module_id']);
		}

		if (isset($this->request->post['name'])) {
			$data['name'] = $this->request->post['name'];
		} elseif (!empty($module_info)) {
			$data['name'] = $module_info['name'];
		} else {
			$data['name'] = '';
		}

		if (isset($this->request->post['status'])) {
			$data['status'] = $this->request->post['status'];
		} elseif (!empty($module_info)) {
			$data['status'] = $module_info['status'];
		} else {
			$data['status'] = '';
		}

		$this->load->model('tool/image');

		if (isset($this->request->post['cust_block'])) {
			$cust_block = $this->request->post['cust_block'];
		} elseif (isset($this->request->get['cust_block'])) {
			$cust_block = $this->request->get['cust_block'];
		} else {
			$cust_block = array();
		}

		$data['cust_block'] = array();

		foreach ($cust_block as $block) {
			if (is_file(DIR_IMAGE . $cust_block['image'])) {
				$image = $cust_block['image'];
				$thumb = $cust_block['image'];
			} else {
				$image = '';
				$thumb = 'no_image.png';
			}

			$data['cust_block'][] = array(
				'title'       => $cust_block['title'],
				'description' => $cust_block['description'],
				'link'        => $cust_block['link'],
				'image'       => $image,
				'thumb'       => $this->model_tool_image->resize($thumb, 100, 100),
				'sort_order'  => $cust_block['sort_order'],
				
			);
		}

		$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);



		$this->load->model('localisation/language');

		$data['languages'] = $this->model_localisation_language->getLanguages();

		$data['header'] = $this->load->controller('common/header');
		$data['column_left'] = $this->load->controller('common/column_left');
		$data['footer'] = $this->load->controller('common/footer');

		$this->response->setOutput($this->load->view('module/info_line.tpl', $data));
	}

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

		if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) {
			$this->error['name'] = $this->language->get('error_name');
		}

		return !$this->error;
	}
}
Все передается в settings модуля но не выходит вернуть обратно в форму

if (isset($this->request->post['cust_block'])) {
			$cust_block = $this->request->post['cust_block'];
		} elseif (isset($this->request->get['cust_block'])) {
			$cust_block = $this->request->get['cust_block'];
		} else {
			$cust_block = array();
		}
Edited by afwollis

Share this post


Link to post
Share on other sites

сказал же - со скриншотом.

Share this post


Link to post
Share on other sites

сказал же - со скриншотом.

Скрин предлагаю 

 

91H8UmFq3iI.jpg

Share this post


Link to post
Share on other sites

С отправкой и получение данных в форму разобрался, не досмотрел немного

 

Но вот другая проблема "на рисовалась"  при первом сохранении данных в форму все хорошо, но если попытаться повторно редактировать получаю null 

Share this post


Link to post
Share on other sites

Урррраа) решено, сам понял де накосячил )  :eek:  :eek:  :eek:  :eek:  :eek:  :eek:  :eek:  :eek:  :eek:

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.