How can I display images in carousel using Codeigniter - codeigniter

I am using CI_3 and successfully inserted images to database and in directory but I can't get the image to display on carousel. How should I properly get the image to display it on a carousel?
(EDITED)
I have this on my Model:
function carousel(){
$this->db->select('*');
$this->db->where('status = 1');
$query = $this->db->get('image');
return $query->result_array();
}
Controller:
public function index()
{
$data['content'] = $this->Home_model->getRows();
$data['title'] = 'Products List';
// Load the list page view
$this->load->view('template/header');
$this->load->view('template/topBarNav');
$image = new Home_model;
$data['images'] = $image->carousel();
$this->load->view('pages/home', $data);
$this->load->view('template/footer');
}
and display it on view like this:
<div class="carousel-inner">
<?php foreach ($images as $row) : ?>
<div class="carousel-item card">
<div class="parent d-flex justify-content-center">
<img id="carousel_image" src="<?php echo base_url('uploads1/'.$row['upload_path']) ; ?>" class="img-responsive">
<div class="carousel-caption">
<h3><?php echo stripslashes(html_entity_decode($row['description'])); ?></h3>
</div>
</div>
</div>
<?php endforeach; ?>
But it doesn't display any images. I only get the folder path of the image and not the actual image.
Every uploaded image will create a folder according to their id, therefore every image are inside the generated folders inside uploads1 where I set the upload path for the images.

Your carousel is not working because your are set every item active that's the issue in this only first item was active only other are automatically active by your carousel .
You can try with removing active in loop make it first active only using condtions
<div class="carousel-inner">
<?php foreach ($images as $i => $row) : ?>
<div class="carousel-item card">
<div class="parent d-flex justify-content-center">
<img src="<?php echo base_url().'tourism/uploads1/'.$row['upload_path'] ?>" class="img-responsive">
<div class="carousel-caption">
<h3><?php echo stripslashes(html_entity_decode($row['description'])); ?></h3>
</div>
</div>
</div>
<?php endforeach; ?>

Related

Glide JS data-glide-dir next is not being rendered correctly

I use Glide JS for a Slideshow that I built with ACF and Gutenberg Blocks.
But there is an issue with the next button. The ">" does not get rendered correctly – and it destroyes the whole DOM. Is there an alternative for the "data-glide-dir" next command? When i remove the data-glide-dir=">" everything works just fine.
Below is the code I use – the screenshot shows how it finally gets rendered in the browser.
screenshot
<?php $gallery = get_field('images'); ?>
<?php if( $gallery ) : ?>
<div class="gcont">
<div class="glide">
<div class="glide__track" data-glide-el="track">
<ul class="glide__slides">
<?php foreach( $gallery as $image ) : ?>
<li class="glide__slide"><img class="full-width-image" src="<?php echo esc_url($image['sizes']['large']); ?>" alt="<?php echo esc_attr($image['alt']); ?>"></li>
<?php endforeach; ?>
</ul>
</div>
<div class="glide__arrows" data-glide-el="controls">
<button class="glide__arrow glide__arrow--prev" data-glide-dir="<">prev</button>
<button class="glide__arrow glide__arrow--next" data-glide-dir=">">next</button>
</div>
</div>
</div>
<?php endif; ?>
What did the trick for me was encoding < with < and > with >
See also: HTML: Should I encode greater than or not? ( > > )

Missing argument in codeigniter

I am new to the codeigniter framework. When I try to load the parameter in codeigniter its showing an error like Missing argument 1. Can anyone please help solve my issue. Here Is my code.
This is My View Code. In view code i call the parameter in ">Read More
<div class="row m-t-20">
<?php foreach($show as $row) { ?>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="recent-pro-box">
<div class="pro-img">
<img src="<?php echo base_url()?>uploads/<?php echo $row['img_path']; ?>" alt="" class="img-responsive" />
</div>
<h2 class="title"><?php echo $row['title'];?></h2>
<p><?php echo $row['message'];?> ...</p>
<div class="more-link">Read More</div>
</div>
</div>
<?php }?>
</div>
Controller code
public function viewProjects($id)
{
$data['show']=$this->Selection_Model->fullProjects($id);
$this->load->view('topurl');
$this->load->view('nav');
$this->load->view('fullProjects',$data);
$this->load->view('footer');
}
Model Code
public function fullProjects($id){
$this->db->select('*');
$this->db->where('p_id',$id);
$this->db->from('projects');
$query = $this->db->get();
$result = $query->row_array();
return $result;
}
Final view code
<div class="col-md-7 ab-text">
<?php foreach($show as $row) { ?>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="recent-pro-box">
<div class="pro-img">
<p><?php echo $row['message'];?> ...</p>
</div>
</div>
<?php }?>
</div>
</div>
In your view.Not need to use foreach loop.Beacuse in codeigniter row_array result set is used to fetch only first matched row. try like this..
<div class="col-md-7 ab-text">
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="recent-pro-box">
<div class="pro-img">
<p><?php echo $show['message'];?> ...</p>
</div>
</div>
</div>
</div>
OR
If you want to use foreach loop.
In model change
$result = $query->row_array();
TO
$result = $query->result_array();
For more see docs Codeigniter Result Sets
All the code's are fine, except one line in Model. Your model should be
function fullProjects($id){
$this->db->select('*');
$this->db->where('p_id',$id);
$this->db->from('projects');
$query = $this->db->get();
$result = $query->result_array(); # Changed
return $result;
}
If you're accessing array data with this pattern $row['message'];, You must use the array as objective array like this $query->result_array();

magento get default view

I have a magento multistore website, I need to list all the store and create a link to their home page, for do it I create this template:
<?php $stores = Mage::app()->getWebsite()->getStores();?>
<?php foreach ($stores as $_store): ?>
<div class="store">
<div class="title">
<?php echo $this->htmlEscape($_store->getName()) ?>
</div>
<div class="description">
<p><?php echo Mage::getStoreConfig('design/head/default_description',$_store->getStoreId()); ?></p>
Vai al sito
<a class="link-to-store" href="<?php echo $this->htmlEscape($_store->getHomeUrl())?>">Vai al Negozio</a>
</div>
</div>
<?php endforeach; ?>
the code works until I have 2 store view, intact the code display all 2 view instead only one, there is a way to display only the store and link to correct home page based on current language?
Take a look # Getting a list of magento stores
foreach (Mage::app()->getWebsites() as $website) {
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach ($stores as $_store) {
<div class="store">
<div class="title">
<?php echo $this->htmlEscape($_store->getName()) ?>
</div>
...
</div>
}
}
}

How to add attribute values to the footer in Magento, as a list?

My products in Magento have attribute Brand. What I need to do is to display a list of Brands in the footer.Something like: Our Brands: Brand 1, Brand 2, Brand 3...
As far as I understand I need somehow retrieve values from Advanced search and display them in footer as a list, but I don't know how to do it. Does anybody have solution for this?
There are several steps to follow
here i am giving detail instruction how to add your custom attribute at footer.
1. you have to create on block to get all your brand product with assign your custom attribute
for block.
$attributes = Mage::getSingleton('eav/config')
->getEntityType(Mage_Catalog_Model_Product::ENTITY) // pass your attribute id
->getAttributeCollection()
->addSetInfo();
foreach ($attributes as $attribute)
{
if ($attribute->usesSource())
{
echo "{$attribute->getFrontendLabel()}:\n";
foreach ($attribute->getSource()->getAllOptions() as $option)
{
echo " {$option['label']}\n";
}
echo "\n";
}
}
above is print logic you should have to store it one array in return with one variable.
2. create view file in your theme for display purpose and call that block function in that home_logo file.
<?php $_brandsCollection = $this->getBrandsLogoCollection();?>
<div class="block block-layered-nav">
<div class="block-title">
<strong><span><?php echo $this->__('Brands') ?></span></strong>
</div>
<div class="block-content" >
<div id="Carousel2" class="carousel">
<div class="button navButton previous" style="display:none;">Back</div>
<div class="button navButton next" style="display:none;">More</div>
<div class="container">
<div class="items">
<?php foreach ($_brandsCollection as $_brand): ?>
<div class="item">
<div class="key caption"></div>
<div class="icon">
<img class="brand-base-logo" alt="<?php echo $_brand->getBrandLogo() ?>" src="<?php echo $_brand->getBrandLogo(); ?>" width="50" height="50">
</div>
<div class="picture">
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div> <!-- end block content-->
</div>
3. Assign that file to footer using your_layout.xml with reference before footer.
<reference name="footer">
<block type="brand/left" name="brands_logolist" before="-" template="brand/home_logo.phtml" />
</reference>
Hope you can understand my logic.

insert a item in to masnory jquery

In a products listing page of magento, i used the masonry and it is working good. But now i want to add a div having some text in the masonry area. I tried this and i get the result, but it break masonry item. My used code...
<?php if ($category_nameplace == round($_collectionSize/2)): ?>
<div class="item">
<h2 class="productcategory-name"><?php echo $this->getLayer()->getCurrentCategory()->getName() ?></h2>
</div>
<?php endif; ?>
This above code is used for insert extra item to the masonry area. In the above code i count the items number and as i got the middle number i insert my div in to bellow written area
<div id="basic" class="products-grid unstyled thubmnails js-masonry">
<?php $category_nameplace = 0; foreach ($_productCollection as $_product): ?>
<?php $category_nameplace++; ?>
<div class="item">
<div class="thumbnail">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(rand(135,400)); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<div class="caption">
<h2 class="product-name product-info"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
<h2 class="product-info"><?php echo "Dimension:".$_product->getDimension(); ?></h2>
<h2 class="product-info"><?php echo $_product->getPrice(); ?></h2>
</div>
</div>
</div>
<?php endforeach ?>
</div>

Resources