site/views/index.php
<?php foreach($pic as $pic_item): ?> {
<img src="<?php echo base_url('assets1/images/slider/'.$pic_item->pic_item );?>">
}
<?php endforeach;
?>
controllers/Cspages.php
public function index()
{
$this->load->model('gallery_model');
$pic_unique_id = 18; // slider
$data['pic'] = $this->gallery_model->get_picture($pic_unique_id);
$this->load->view('index', $data);
}
models/Gallery_model.php
public function get_picture($pic_unique_id)
{
$query = $this->db->get_where('galleries_pictures', array('picture_unique_id' => $pic_unique_id));
return $query->result();
}
How to fix the following error?
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$pic_item
Filename: views/index.php
Line Number: 214
Backtrace:
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\index.php
Line: 214
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\controllers\Cspages.php
Line: 31
Function: view
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\index.php
Line: 315
Function: require_once
http://localhost/masterlinkci2/assets1/images/slider/"> }
Change your foreach loop in view as below:
<?php foreach($pic as $pic_item): ?>
<img src="<?php echo base_url('assets1/images/slider/').$pic_item->pic_item;?>">
<?php endforeach;?>
OR
<?php foreach($pic as $pic_item): ?>
<img src="<?php echo base_url('assets1/images/slider/'.$pic_item->pic_item );?>">
<?php endforeach;?>
UPDATE
Model
<?php
public function get_picture($pic_unique_id)
{
$this->db->where('picture_unique_id',$pic_unique_id);
$query = $this->db->get_where('galleries_pictures');
return $query->row;
}
Controller
public function index()
{
$this->load->helper('url');//load url helper
$this->load->model('gallery_model');
$pic_unique_id = 18; // slider
$data['pic'] = $this->gallery_model->get_picture($pic_unique_id);
$this->load->view('index', $data);
}
view
<img src="<?php echo base_url('assets1/images/slider/'.$pic->pic_item );?>">
Related
Actually I am working on front-end, but I cannot reach the backend developer and I need to fix a bug.
The problem is exactly this, if there is no image in a content, we get an error like this:
A PHP Error was encountered
A
Severity: Notice
Message: Undefined property: stdClass:$Pictures
Filename:agent/hotel_detail.php
Line Number: 17
Backtrace:
File:/home/tungatour/public_html/application/views/agent/hotel_detail.php
Line: 17
Function: _error_handler
File:/home/tungatour/public_html/application/controllers/Agent.php
Line: 490
Function: view
File:/home/tungatour/public_htm/index.php
I just want to show demo image instead if there is no image. But i dont have any idea how can i do this ?
so i have controller codes about picture this this.
public function post($ID)
{
$viewData["title"] = "Post Details";
$data = $this->db->where("ID", $ID)->get("post")->row();
$data->Meta = json_decode($data->Meta);
$picture = $this->db->where("ID", $data->Meta->Thumbnail)->get("picture")->row();
$viewData["data"] = $data;
$viewData["picture"] = $picture;
$this->load->view('partials/agent/head', $viewData);
$this->load->view('agent/post', $viewData);
$this->load->view('partials/agent/foot', $viewData);
}
also i have this lines` <?php $first = true;
for ($i = 0; $i < $this->db->where_in("ID", $data->Meta->Pictures)->count_all_results("picture"); $i++) { ?>
<li data-target="#carousel-example-generic" data-slide-to="<?= $i ?>" class="<?= $first ? "active" : "" ?>"></li>
<?php $first = false;
} ?>
</ol>
<div class="carousel-inner" role="listbox">
<?php $first = true;
foreach ($this->db->where_in("ID", $data->Meta->Pictures)->get("picture")->result() as $picture) { ?>
<div class="carousel-item <?= $first ? "active" : "" ?>">
<img class="img-fluid" src="<?= $picture->URL ?>" style="height: 420px;width: 100%;object-fit: cover;" />
</div>
<?php $first = false;
} ?>
</div>`
Change this line
<img class="img-fluid" src="<?= $picture->URL ?>" style="height: 420px;width: 100%;object-fit: cover;" />
Update with
<?php if($picture->URL) { ?>
<img class="img-fluid" src="<?= $picture->URL ?>" style="height: 420px;width: 100%;object-fit: cover;" />
<?php } ?>
If the image has a URL, it will display the image. Otherwise it will be empty.
I am trying to show picture in codeigniter. Either one or few pictures that I store in the gallery.
gallery_model.php
class Gallery_model extends CI_Model {
public function get_picture($pic_unique_id)
{
$query = $this->db->get('galleries_pictures', $pic_unique_id);
return $query->result();
}
}
controllers/cspages.php
public function index()
{
$this->load->gallery_model();
$this->load->get_picture($pic_unique_id);
$this->load->view('index');
}
views/index.php
<?php foreach($pic as $pic_item) { ?>
<?php endforeach; } ?>
<!-- MAIN IMAGE -->
<img src="<?php echo base_url(); ?>assets1/images/slider/1.jpg">
How to get the $pic_unique_id and $pic_item ?
Try This IN model:
class Gallery_model extends CI_Model {
public function get_picture($pic_unique_id)
{
$query = $this->db->get_where('galleries_pictures',array('pic_id'=> $pic_unique_id));
return $query->result();
}
}
IN Controller:
public function index()
{
$this->load->helper('url');
$this->load->model('gallery_model');//loads model
$data['pic'] = $this->gallery_model->get_picture($pic_unique_id);//calls to model function
$this->load->view('index',$data);//loads view with data
}
IN view
<?php foreach($pic as $pic_item) { ?>
<img src="<?php echo base_url(assets1/images/slider/).$pic_item->pic_item; ?>">
<?php } ?>
Try this in gallery_model.php
class Gallery_model extends CI_Model {
public function get_picture($pic_unique_id)
{
$query = $this->db->get_where('galleries_pictures',array('pic_id'=> $pic_unique_id));
return $query->result();
}
}
Try this in controllers/cspages.php
public function index()
{
$this->load->gallery_model();
$data['pic'] = $this->load->get_picture($pic_unique_id);
$this->load->view('index',$data);
}
in views/index.php
<?php foreach($pic as $pic_item) { ?>
<img src="<?php echo base_url(); ?>assets1/images/slider/<?= $pic_item->pic_item ?> ">
<?php endforeach; } ?>
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: views/editslideshows.php
Line Number: 56
Backtrace:
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\views\editslideshows.php
Line: 56
Function: _error_handler
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\controllers\Cpages.php
Line: 310
Function: view
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\index.php
Line: 315
Function: require_once
views/editslideshows.php
<?php foreach ($images as $images_item): ?>
<?php echo $images; ?>
<?php endforeach; ?>
controllers/Cpages.php
public function editslideshow() {
$image_id = $this->uri->segment(3);
$data['images'] = $this->Mpages->call_point_slideshow($image_id);
$this->load->view('editslideshows', $data);
}
models/Mpages.php
public function call_point_slideshow($image_id)
{
$this->db->where('image_id', $image_id);
$query = $this->db->get('slideshow');
return $query->result();
}
In your view page views/editslideshows.php
You used echo directly <?php echo $images; ?> that's why you getting error.
You can use $images_item->db_field_name. that's means any field name from your slideshow table
bellow my correction :
<?php foreach ($images as $images_item): ?>
<?php echo $images_item->db_field_name; ?>
<?php endforeach; ?>
In your view
<?php foreach ($images as $images_item) { ?>
<h3><?php echo $images_item->field_name; ?></h3>
<?php } ?>
I am using opencart version 2.0.2.0 and now i am trying to get image or image url in manufacturer page.
I have added the code in catalog/controller/product/manufacturer.php
$manufacturer_image = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
if($manufacturer_image){
$this->data['manufacturers_img'] = $this->model_tool_image->resize($manufacturer_image['image'], 120, 120);
}else{
$this->data['manufacturers_img'] = false;
}
and call it in catalog/view/theme/default/template/product/manufacturer_list.tpl
<div class="row">
<?php foreach ($manufacturers as $manufacturer) { ?>
<div class="col-sm-3"><?php echo $manufacturer['name']; ?>
<?php echo ($manufacturers_img) ? '<img src="'.$manufacturers_img.'" alt="'.$manufacturers.'" />' : $manufacturers ;?><br />
</div>
<?php } ?>
</div>
But it's getting error in my /index.php?route=product/manufacturer page
Notice: Undefined variable: manufacturers_img in
/data1/opencart-2.0.2.0/catalog/view/theme/default/template/product/manufacturer_list.tpl
on line 32Array
lets be clear ControllerProductManufacturer index() shows list and info() shows detail of the mfg,
//catalog/controller/product/manufacturer.php:46
Replace
$data['categories'][$key]['manufacturer'][] = array(
with
$manufacturer_image = $this->model_catalog_manufacturer->getManufacturer($result['manufacturer_id']);
if($manufacturer_image){
$mfg_img = $this->model_tool_image->resize($manufacturer_image['image'], 120, 120);
}else{
$mfg_img = false;
}
$data['categories'][$key]['manufacturer'][] = array(
'image'=>$mfg_img,
And in catalog/view/theme/default/template/product/manufacturer_list.tpl:30
inside loop
<?php if($manufacturer['image']):?>
<img src="<?php echo $manufacturer['image']; ?>" alt="<?php echo $manufacturer['name'];?>">
<?php endif;?>
I am new to Codeigniter and want to export data present in my MYSQL database into PDF file using MPDF. The code is as follows:
View:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Export PDF</title>
</head>
<body>
<div id="container">
<h4>Member Data</h4>
<table border="1">
<tr>
<th>group_id</th>
<th>group_name</th>
<th>Archieved</th>
</tr>
<?php
foreach ($member as $rows) {
echo $rows['group_id'];
?>
<tr>
<td><?php echo $rows['group_id'] ?></td>
<td><?php echo $rows['group_name']?></td>
<td><?php echo $rows['archieved'] ?></td>
</tr>
<?php
$i++;
}
?>
</table>
<br> <br>
<a href='<?php echo base_url(); ?>index.php/member_con/topdf'><span style='color:green;'>Export to Pdf</span></a>
</div>
<?php
?>
</body>
</html>
Controller:
<?php
class Member_con extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('member_model');
$this->load->helper('url');
$this->load->library('mpdf');
}
public function index() {
$data['member'] = $this->member_model->alldata();
$this->load->view('member_view', $data);
}
function topdf() {
$this->mpdf->useOnlyCoreFonts = true;
$filename = "VISH";
$data['member'] = $this->member_model->alldata();
$html = $this->load->view('member_view', $data['member'], true);
$this->mpdf->setTitle('Posts');
$this->mpdf->writeHTML($html);
$this->mpdf->output($filename, 'D');
}
}
?>
Model:
<?php
class Member_model extends CI_Model {
function __construct() {
parent::__construct();
$this->load->database();
}
function Member_Model() {
parent::Model();
}
function alldata()
{
$this->db->select('*');
$this->db->from('groups');
$this->db->order_by('group_id','ASC');
$getData = $this->db->get();
if($getData->num_rows() > 0)
return $getData->result_array();
else return null;
}
}
?>
with this code, it is giving me a blank PDF file, with only text as 'Member Data' and 'Export as pdf'. I have checked whether it is passing data to view, and yes it is doing so.
But don't know what is the matter with 'foreach' loop. I is printing everything outside 'foreach' loop, but bot the data members. Can anyone please let me know what should I do?
Thanks in advance....
Got the answer. In controller, instead of
$html = $this->load->view('member_view', $data['member'], true);
I used following:
$html = $this->load->view('member_view', $data, true);