Jump to content
Sign in to follow this  
Dozent

Вывод баннера в произвольном месте по ID

Recommended Posts

добрый вечер форумчане
добавил в контроллере catalog/controller/extension/module/banner.php

'banner_id' => $result['banner_id'],

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

<?php foreach ($banners as $banner) { ?>
<?php if ($banner['banner_id'] == 5) { ?>
<div class="col-xs-2">
 <a href="<?php echo $banner['link']; ?>"><img src="<?php echo $banner['image']; ?>"></a>
</div><!-- end col-xs-2 -->
<?php } ?>
<?php } ?>

ругается на ошибки  Invalid argument supplied for foreach() in : Undefined variable: banners in  

Share this post


Link to post
Share on other sites

откуда в шапке эта переменная? нужно же наверное запрос какой то добавить чтоб получить баннер?

Share this post


Link to post
Share on other sites
Posted (edited)
1 час назад, AUSS сказал:

откуда в шапке эта переменная? нужно же наверное запрос какой то добавить чтоб получить баннер?

думаю да, насколько я понимаю нужно сделать запрос в контроллере header.php?
можете пожалуйста подсказать какой нужно

Edited by Dozent

Share this post


Link to post
Share on other sites
Posted (edited)
$this->load->model('design/banner');
$this->load->model('tool/image');

$data['banners'] = array();
$results = $this->model_design_banner->getBanner(5);

foreach ($results as $result) {
if (is_file(DIR_IMAGE . $result['image'])) {
$data['banners'][] = array(
'title' => $result['title'],
'link'  => $result['link'],
'image' => $this->model_tool_image->resize($result['image'], ширина, высота)
);
}
}

Попробуйте примерно так - код взят из ControllerExtensionModuleSlideshow

Edited by AUSS
  • +1 1

Share this post


Link to post
Share on other sites

вот решение

 

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

$data['banners'] = array();
$results = $this->model_design_banner->getBanner(5);

foreach ($results as $result) {
if (is_file(DIR_IMAGE . $result['image'])) {
$data['banners'][] = array(
'banner_id' => $result['banner_id'],
'title' => $result['title'],
'link'  => $result['link'],
'image' => $this->model_tool_image->resize($result['image'],1000, 500)
);
}
}

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.