getting error on uploading multiple images using codeigniter - php

when uploading multiple images iam getting an error that the value of table is getting null while displaying..
here is my controler..
public function add_images()
{
$data['active_mn']='add_images';
$this->form_validation->set_rules('title','title','required');
$this->form_validation->set_rules('parentname','parent category','required');
$this->form_validation->set_rules('subname','sub category','required');
$this->form_validation->set_rules('code','code','required');
$this->form_validation->set_rules('description','Description','required');
$this->form_validation->set_rules('size','Size','required');
if($this->form_validation->run()==TRUE)
{
$image=array_values($this->session->userdata('image'));
$images=json_encode($image);
$data = array('title'=>$this->input->post('title'),
'code'=>$this->input->post('code'),
'select_image'=>$this->input->post('select_image'),
'select_wear'=>$this->input->post('select_wear'),
'image'=>$images,
'category_id'=>$this->input->post('subname'),
'size'=>$this->input->post('size'),
'description'=>$this->input->post('description'));
$product=$this->roxmodel->add_gallery($data);
if($product)
{
$data=array();
$colors=array_filter($this->session->userdata('colors'));
/*creating a multidiemensional array to batch insert*/
foreach ($colors as $color)
{
$new_array=array('product_id'=>$product,'color'=>$color);
array_push($data, $new_array);
}
$product=$this->roxmodel->add_product_color($data);
$this->session->unset_userdata('image');
$this->session->unset_userdata('colors');
$this->session->set_flashdata('message', 'Product added Successfully.');
redirect('admin_control/view_images');
}
else
{
//$this->session->unset_userdata('image');
$this->session->set_flashdata('message', 'Insertion Failed.');
redirect('admin_control/add_images');
}
}
//$this->session->unset_userdata('image');
//var_dump($data['sub_category']);
$data['parent']=$this->roxmodel->get_parentcategory();
$this->load->view('add_images',$data);
}
my view page is this...
<?php foreach ($detail as $row) { ?>
<div class="col-md-3 col-sm-1">
<?php $images = json_decode($row->image);
//print_r($images); ?>
<div class="image-box">
<!-- <textarea id="F<?php echo $row->id;?>" hidden> <?php echo $row->image;?></textarea>
<img width="100" src="<?php echo base_url()?>images/<?php echo $images[0] ?>" alt="" file="F<?php echo $row->id;?>" class="img-responsive view-more">
-->
<?php
if($images){
foreach($images as $image):?>
<img width="100" height="100" src="<?php echo base_url();?>images/<?php echo $image;?>" class="img-responsive" alt="">
<?php endforeach;
}
else
{
?>
<img width="100" height="100" src="<?php echo base_url();?>images/<?php echo $row->image;?>" class="img-responsive" alt="">
<?php
};
?>
<div class="edit-box">
<h4><?php echo $row->title; ?>
</h4>
<span class="rg-br" type="button">
<i class="fa fa-pencil-square-o" data-toggle="tooltip" data-placement="bottom" title="Edit"></i>
</span>
<span>
<a class="portfolio" data-toggle="modal" onclick='return deleteItem()' name="delete" id="title" img="img1446224811.jpg" big-img="" title="Delete" href="<?php echo base_url();?>admin_control/delete_image/<?php echo $row->id;?>/<?php echo $row->image;?>"><i class="fa fa-trash-o" data-toggle="tooltip" data-placement="bottom" title="Delete"></i></a></span>
<h5><!-- <?php echo $row->description; ?> --></h5>
</div>
</div>
</div>
<?php } ?>
here the image is not displaying and the value of image in table is getting null

Related

Magento category to owl carousel

This code is displaying only one product from each category, however I want it to display all products from each category in its own owl-carousel.
How can I fix this?
<?php
$categoryIds = array("3","5","6","12","7");
foreach($categoryIds as $categoryId){
$carouselcategoryProducts = $block->getCategoryProductsById($categoryId);
foreach ($carouselcategoryProducts as $carouselproduct) {
/*Get Thumbnail*/
$carouselimageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct');
$carouselproductImage = $carouselimageBlock->getImage($carouselproduct, 'category_page_grid');
?>
<div class="owl-carousel owl-theme">
<h4 class="item">
<a href="<?php echo $carouselproduct->getProductUrl(); ?>">
<div class="product_row2">
<div class="product_column2">
<img class="product_img2" <?php echo $carouselproductImage->toHtml(); ?><i class="far fa-clone compare"></i>
<p class="product_title2"><?php echo $carouselproduct->getName(); ?></p>
<p class="product_price2">€ <?php echo $carouselproduct->getFinalPrice(); ?>,-</p>
</div>
</div>
</a>
</h4>
</div>
<?php
}
}
?>
Fixed the issue.
Correct code:
<?php
$categoryIds = array(3,5,6,12,7);
foreach($categoryIds as $categoryId) :
//echo "<p>category id: </p>$categoryId";
$carouselcategoryProducts = $block->getCategoryProductsById($categoryId);
echo "<div class=\"owl-carousel owl-theme\">";
foreach ($carouselcategoryProducts as $carouselproduct) :
//Get Thumbnail
$carouselimageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct');
$carouselproductImage = $carouselimageBlock->getImage($carouselproduct, 'category_page_grid');
?>
<h4 class="item">
<a href="<?php echo $carouselproduct->getProductUrl(); ?>">
<div class="product_row2">
<div class="product_column2">
<img class="product_img2" <?php echo $carouselproductImage->toHtml(); ?><i class="far fa-clone compare"></i>
<p class="product_title2"><?php echo $carouselproduct->getName(); ?></p>
<p class="product_price2">€ <?php echo $carouselproduct->getFinalPrice(); ?>,-</p>
</div>
</div>
</a>
</h4>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
Correct Code:
$categoryIds = array(3,5,6,12,7);
foreach ($categoryIds as $cat)
{
$_category = $objectManager->create('Magento\Catalog\Model\Category')->load($cat);
echo "<div class=\"owl-carousel owl-theme\">";
$categoryProducts = $_category->getProductCollection()
->addAttributeToSelect('*');
foreach ($categoryProducts as $product) {?>
<h4 class="item">
<a href="<?php echo $product->getProductUrl(); ?>">
<div class="product_row2">
<div class="product_column2">
<img class="product_img2" <?php echo $product->toHtml(); ?><i class="far fa-clone compare"></i>
<p class="product_title2"><?php echo $product->getName(); ?></p>
<p class="product_price2">€ <?php echo $product->getFinalPrice(); ?>,-</p>
</div>
</div>
</a>
</h4>
}
echo "</div>";
}

dynamic image path for lightgallery plugin

We have already added the code,but only thumb images are displaying.we want natural image path.
I have attached image reference,Please go through this
<div class="<?php echo $class; ?>">
<?php if ($thumb || $images) { ?>
<ul class="thumbnails" id="lightgallery" >
<?php if ($thumb) { ?>
<li class="col-xs-6 col-sm-4 col-md-3 prdbimgImg img-responsive" data-responsive="<?php echo $thumb; ?>" data-src="<?php echo $thumb; ?>" >
<a href="" id="zoom_01">
<img class="img-responsive" src="<?php echo $thumb; ?>" data-zoom-image="<?php echo $popup; ?>">
</a>
</li>
<?php } ?>
<?php if ($images) { ?>
<?php foreach ($images as $image) { ?>
<li class="image-additional img-responsive" data-responsive="<?php echo $image['thumb']; ?>" data-src="<?php echo $image['thumb']; ?>" >
<a href="" data-id="zoom_01">
<img class="img-responsive" src="<?php echo $image['thumb']; ?>" data-zoom-image="<?php echo $popup; ?>">
</a>
</li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
</div>
That's because you're setting your thumbnail to data-src:
data-src="<?php echo $image['thumb']; ?>"
According to the docs, data-src should contain the full image.
If the images are stored in $images and thumbnails in $thumb as you say, then this should do the trick:
<ul id="lightGallery" >
<?php for ($i = 0; $i < count($images); $i++) { ?>
<li data-src="<?php echo $images[$i]; ?>" >
<img src="<?php echo $thumb[$i]; ?>" />
</li>
<?php } ?>
</ul>

Jump to a specific tab in WordPress

I have a code which works on my localhost but does not work when I implement it on my live site, which is hosted on WordPress.
I have the below code on another page:
<div class="smaller-col col-xs-6 col-md-3 product-thumb">
<a href='<?php echo "/the-pods#{$product_id}"; ?>' target="_blank" class="thumbnail">
<img class="img-responsive animated pulse eds-on-hover" src="<?php echo $product_image; ?>" width="120" height="120" alt="Hello Paisa">
</a>
<p><?php echo $product_tagline; ?></p>
</div>
The above page links to the page with the code below:
<div id="exTab1" class="">
<ul class="nav nav-pills">
<?php
$counter = 0; while($products->fetch()):
$product_id = $products->field('product_id');
$product_image = wp_get_attachment_url($products->get_field('product_logo.ID'));
?>
<li class="<?php if($counter == 0){ echo 'active'; } ?>">
<a href='<?php echo "#$product_id"; ?>' data-toggle="tab">
<img class="img-responsive" src="<?php echo $product_image; ?>"/>
</a>
</li>
<?php $counter++; endwhile; ?>
</ul>
<div class="tab-content">
<?php
$counter_2 = 0; while($products_2->fetch()):
$product_id_2 = $products_2->field('product_id');
$product_image_2 = wp_get_attachment_url($products_2->get_field('product_logo.ID'));
$product_desc_2 = $products_2->field('product_description');
$product_website_2 = $products_2->field('product_website');
?>
<div class="tab-pane <?php if($counter_2 == 0){ echo 'active'; } ?> fade in" id="<?php echo $product_id_2; ?>">
<?php echo '#' . $product_image_2; ?>
<?php echo "<p style='color:#777;'>" . $product_desc_2 . "</p>";?>
<?php echo $product_website_2; ?>
</div>
<?php $counter_2++; endwhile; ?>
</div>
</div>
<script>
var tabUrl = document.location.toString();
if(tabUrl.match('#')) {
$('.nav-pills a[href="#' + tabUrl.split('#')[1] + '"]').tab('show');
}
$('#nav-pills a').on('shown.bs.tab', function(e) {
window.location.hash = e.target.hash;
});
</script>
How do I implement the navigation part properly on Wordpress?

opencart 2.x not passing value from latest product module to view

By default Opencart latest product shows prod name,product description and price but now I want product booking prices(new field added for all the products) in latest product section so I changed my latest product code and added code to show booking price. Here is the complete code for latest product.
<?php
class ControllerModuleLatest extends Controller {
public function index($setting) {
$this->load->language('module/latest');
$data['heading_title'] = $this->language->get('heading_title');
$data['text_tax'] = $this->language->get('text_tax');
$data['button_cart'] = $this->language->get('button_cart');
$data['button_wishlist'] = $this->language->get('button_wishlist');
$data['button_compare'] = $this->language->get('button_compare');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$data['products'] = array();
$filter_data = array(
'sort' => 'p.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => $setting['limit']
);
$results = $this->model_catalog_product->getProducts($filter_data);
if ($results) {
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = $result['rating'];
} else {
$rating = false;
}
$data['product']=$result['product_id'];
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'booking_price' => $result['booking_price'],
'tax' => $tax,
'rating' => $rating,
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/latest.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/module/latest.tpl', $data);
} else {
return $this->load->view('default/template/module/latest.tpl', $data);
}
}
}
}
latest.tpl
<script>
jQuery(document).ready(function(){
$(".quickview-latest").fancybox({
maxWidth : 800,
maxHeight : 600,
fitToView : false,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'elastic',
closeEffect : 'elastic',
});
});
</script>
<div class="box latest">
<div class="box-heading"><h3><?php echo $heading_title; ?></h3></div>
<div class="box-content">
<div class="row">
<?php $g=0; foreach ($products as $product) { $g++ ?>
<div class="product-layout col-lg-3 col-md-3 col-sm-3 col-xs-6">
<div class="product-thumb transition">
<a class="quickview quickview-latest" data-rel="details" href="#quickview_latest_<?php echo $g?>">
<?php echo $text_quick; ?>
</a>
<div class="quick_info">
<div id="quickview_latest_<?php echo $g?>">
<div>
<div class="left col-sm-4">
<div class="quickview_image image"><img alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" src="<?php echo $product['thumb']; ?>" /></div>
</div>
<div class="right col-sm-8">
<h2><?php echo $product['name']; ?></h2>
<div class="inf">
<?php if ($product['author']) {?>
<p class="quickview_manufacture manufacture manufacture"><?php echo $text_manufacturer; ?> <?php echo $product['author']; ?></p>
<?php }?>
<?php if ($product['model']) {?>
<p class="product_model model"><?php echo $text_model; ?> <?php echo $product['model'];
?></p>
<?php }?>
<?php if ($products['booking_price']) {?>
<p class="product_model model"><?php echo $text_model; ?> <?php echo $products['booking_price'];
?></p>
<?php }?>
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price'];?>
<?php } else { ?>
<span class="price-new"><?php echo $product['special']; ?></span> <span class="price-old"><?php echo $product['price']; ?></span>
<?php } ?>
<?php if ($product['tax']) { ?>
<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
<?php } ?>
</div>
<?php } ?>
</div>
<div class="cart-button">
<button type="button" class="btn btn-icon" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-star"></i></button><button type="button" class="btn btn-icon" data-toggle="tooltip" title="<?php echo $button_compare; ?>" onclick="compare.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-exchange"></i></button><button type="button" class="btn btn-icon btn-add" data-toggle="tooltip" title="<?php echo $button_cart; ?>" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i></button>
</div>
<div class="clear"></div>
<div class="rating">
<?php for ($i = 1; $i <= 5; $i++) { ?>
<?php if ($product['rating'] < $i) { ?>
<span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i></span>
<?php } else { ?>
<span class="fa fa-stack"><i class="fa fa-star active fa-stack-2x"></i></span>
<?php } ?>
<?php } ?>
</div>
</div>
<div class="col-sm-12">
<div class="quickview_description description">
<?php echo $product['description1'];?>
</div>
</div>
</div>
</div>
</div>
<div class="image">
<a href="<?php echo $product['href']; ?>">
<img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" />
</a>
<div class="new_pr"><?php echo $text_new; ?></div>
</div>
<div class="caption">
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-new">
<?php echo $product['special']; ?>
</span>
<span class="price-old">
<?php echo $product['price']; ?>
</span>
<?php } ?>
<?php if ($product['tax']) { ?>
<span class="price-tax">
<?php echo $text_tax; ?> <?php echo $product['tax']; ?>
</span>
<?php } ?>
</div>
<?php } ?>
<?php if ($product['booking_price']) {?>
<p class="product_model model"><?php echo $text_model; ?> <?php echo $product['booking_price'];
?></p>
<?php }?>
<div class="name">
<a href="<?php echo $product['href']; ?>">
<?php echo $product['name']; ?>
</a>
</div>
<div class="description"><?php echo mb_substr($product['description'],0,84,'UTF-8').'...'; ?></div>
<div class="rating">
<?php for ($i = 1; $i <= 5; $i++) { ?>
<?php if ($product['rating'] < $i) { ?>
<span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i></span>
<?php } else { ?>
<span class="fa fa-stack"><i class="fa fa-star active fa-stack-2x"></i></span>
<?php } ?>
<?php } ?>
</div>
</div>
<div class="cart-button">
<button class="btn btn-icon" type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-star"></i></button><button class="btn btn-add" type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><span><?php echo $button_cart; ?></span></button>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
i am getting this error
Notice: Undefined index: booking_price in C:\wamp\www\royal\catalog\view\theme\theme546\template\module\latest.tpl on line 114
Any help and suggestions will be appreciable.Thanks in advance.
If I have understood your issue rightly and you want to display in your store a value which isn't set in the controller, I would personally use a vQmod extension (such as this one) rather than directly affect a controller file.

Dynamic CSS ID with PHP

A newbie here. Trying to increment CSS ID selector with PHP.
Following the code I have
<?php
$thumbnails = get_post_meta($post->ID, "plans", false);
if ($thumbnails[0] != '') :?>
<div id="images-box">
<?php foreach($thumbnails as $thumb) {
echo '<div class="holder">
<div id="image-'. $id .'" class="image-lightbox">
<span class="close">X</span>
<img src="' . $thumb . '" alt="" />
<a class="expand" href="#image-1"></a>
</div>';
} ?>
</div>
<?php endif; ?>
What I want is
<div id="image-1" class="image-lightbox">
<div id="image-2" class="image-lightbox">
<div id="image-3" class="image-lightbox">
I tried with many options that were answered here (http://codepad.org/OHuTxQPI) but couldn't get it right.
Simply add $id=1; and $id++; in your code.
<?php
$id = 1;
foreach($thumbnails as $thumb) {
echo '<div class="holder">
<div id="image-'. $id .'" class="image-lightbox">
<span class="close">X</span>
<img src="' . $thumb . '" alt="" />
<a class="expand" href="#image-1"></a>
</div>';
$id++;
} ?>
Edited: $id=1; should be used if you want to start from id='image-1'.
You're using $id as a counter but don't actually define or increment anywehre.
<?php
$thumbnails = get_post_meta($post->ID, "plans", false);
if ($thumbnails[0] != '') :?>
<div id="images-box">
<?php
$id = 0;
foreach($thumbnails as $thumb) {
echo '<div class="holder">
<div id="image-'. $id .'" class="image-lightbox">
<span class="close">X</span>
<img src="' . $thumb . '" alt="" />
<a class="expand" href="#image-1"></a>
</div>';
$id++;
} ?>
</div>
<?php endif; ?>
Unlike the rest, I'm using a straight for() loop instead of foreach() to give more control (ok it's really just cuz I'm OCD and like to use $i).
Here's the demo
PHP:
<?php
$thumbnails = array(0 => array('thumb' => 'image.jpg'), 1 => array('thumb' => 'image2.jpg'));
// $thumbnails = get_post_meta($post->ID, "plans", false);
if (isset($thumbnails)): ?>
<div id="images-box">
<?php
$i = 0;
$thumbs = count($thumbnails);
for($i;$i < $thumbs;$i++) { ?>
<div class="holder">
<div id="image-<?php print $i; ?>" class="image-lightbox">
<span class="close">X</span>
<img src="<?php print $thumbnails[$i]['thumb']; ?>" alt="" />
<a class="expand" href="#image-<?php print $i; ?>"></a>
</div>
<?php }; ?>
</div>
<?php endif; ?>
HTML output:
<div id="images-box">
<div class="holder">
<div id="image-0" class="image-lightbox">
<span class="close">X</span>
<img src="image.jpg" alt="" />
<a class="expand" href="#image-0"></a>
</div>
<div class="holder">
<div id="image-1" class="image-lightbox">
<span class="close">X</span>
<img src="image2.jpg" alt="" />
<a class="expand" href="#image-1"></a>
</div>
</div>
Use Counter for $id as told by John or use $id as index for foreach loop as below.
<?php
$thumbnails = get_post_meta($post->ID, "plans", false);
if ($thumbnails[0] != '') :?>
<div id="images-box">
<?php foreach($thumbnails as $id=> $thumb) {
echo '<div class="holder">
<div id="image-'. $id .'" class="image-lightbox">
<span class="close">X</span>
<img src="' . $thumb . '" alt="" />
<a class="expand" href="#image-1"></a>
</div>';
} ?>
</div>
<?php endif; ?>

Categories