Array to string conversion Line Number: 56 - codeigniter

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 } ?>

Related

Why this error appears stdClass::$pic_item?

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 );?>">

Strange replace on magento URL

For some reason, only on view-mode icons on the product list, the "?" of the urls are replaced to "#21". Ex.: "#%21mode=list"
Somebody can help me?
Some code:
app/design/frontend/default/themename/template/catalog/product/list/toolbar.phtml
<?php if( $this->isEnabledViewSwitcher() ): ?>
<p class="view-mode">
<?php $_modes = $this->getModes(); ?>
<?php if($_modes && count($_modes)>1): ?>
<label><?php echo $this->__('View as') ?>:</label>
<?php foreach ($this->getModes() as $_code=>$_label): ?>
<?php if($this->isModeActive($_code)): ?>
<strong title="<?php echo $_label ?>" class="<?php echo strtolower($_code); ?>"><?php echo $_label ?></strong>
<?php else: ?>
<?php echo $_label ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</p>
<?php endif; ?>
app/code//core/Mage/Catalog/Block/Product/List/Toolbar.php
public function getModeUrl($mode)
{
return $this->getPagerUrl( array($this->getModeVarName()=>$mode, $this->getPageVarName() => null) );
}
and...
public function getPagerUrl($params=array())
{
$urlParams = array();
$urlParams['_current'] = true;
$urlParams['_escape'] = true; // I already tried set false, but didn't helps
$urlParams['_use_rewrite'] = true;
$urlParams['_query'] = $params;
return $this->getUrl('*/*/*', $urlParams); // I also tried not use the getUrl and concat the querystring, strangely the replace still happends...
}
I couldn't find the problem, but I make a dirt solution:
<?php echo str_replace('#%21', '&', $this->getModeUrl($_code)); ?>
I wish somebody find a better solution :)

Get specific category level

How can I get a specific category level from Magento, my category setup looks like this now.
root_catalog
|-Shop
|-Shoes
|-T-shirts
|-Brands
|-Nike
|-Womens
|-Mens
|-Adidas
|-Asics
<?php if( $category = Mage::getModel('catalog/category')->load( $categories[1]) ): ?>
<?php echo $category->getName(); ?>
<?php endif ?>
When calling $category->getName(); I would like to only display the Brand Name, is that possible?
You can get category level from
$category = Mage::getModel('catalog/category')->load( $categories[1]) )->getLevel()
and then check with your brand name category level, if match then display name.
e.g. suppose brand category level is 3
<?php if( $category = Mage::getModel('catalog/category')->load( $categories[1]) ): ?>
<?php if($category->getLevel() == 3)
echo $category->getName(); ?>
<?php endif ?>
<?php endif ?>
ANKIT's answer is good, but it could be improved by actually query-ing the specific levels instead of loading the whole collection and doing a conditional. Take for example if you want to get all categories in a specific level:
<ul>
<?php $categories = Mage::getModel('catalog/category')
->getCollection()
// magic is prepared here..
->addAttributeToSelect('*')
// then the magic happens here:
->addAttributeToFilter('level', array('eq'=>2))
->load();
foreach($categories as $category):
?>
<li>$category->getName()</li>
<?php endforeach; ?>
</ul>
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
$categories = $product->getCategoryIds(); /*will return category ids array*/
foreach($categories as $category){
$cat = $objectManager->create('Magento\Catalog\Model\Category')->load($category);
if ($cat->getLevel() == 2) {
$catName = $cat->getName().","; ?>
<div class="brand_bg">
<label><?php /* #escapeNotVerified */ echo __('Category :') ?></label>
<?php echo $catName; ?>
</div>
<?php } ?>
<?php } ?>
?>

Get bundle product items in cart of Magento

Pls help me in my trouble. I need to get bundle products from cart of magento, and than I need to get the selected items of every bundle product. How can I do this? Thanx!
In magento 1.8.1
$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $_item) :
$_product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
if($_product->getTypeId()==='bundle') :
$options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
?>
<dl class="item-options">
<?php foreach ($options['bundle_options'] as $option):?>
<dt><?php echo $option['label'] ?></dt>
<?php foreach ($option['value'] as $sub) :?>
<dd><?php echo $sub['qty'] . " x " . $sub['title'] . " " . Mage::helper('core')->currency($sub['price']) ?></dd>
<?php endforeach;
endforeach;
?>
</dl>
<?php endif;
endforeach
$optionCollection = $product->getTypeInstance()->getOptionsCollection();
$selectionCollection =$product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
$options = $optionCollection->appendSelections($selectionCollection);
foreach( $options as $option )
{
$_selections = $option->getSelections();
foreach( $_selections as $selection )
{
$product_simple = Mage::getModel('catalog/product')->load($selection->getId());
}
}
Hope this will work for you. :)
Best of luck.
$_product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
if($_product->getTypeId()==='bundle') {
$options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
?>
<dl class="item-options">
<?php
foreach ($options['bundle_options'] as $option) {?>
<dt><?php echo $option['label'] ?></dt>
<dd><?php echo $option['value'][0]['title'] ?></dd>
<?php
}
?>
</dl>
<?php }
This work for Input Type "Dropdown" for bundle items

List object properties delimited by comma in CodeIgniter with DataMapper OverZealous Edition

I have 2 classes - Students and Groups with many-to-many relationship. On a student page, I want to show all his details and list all groups he belongs to, delimited by comma.
This is my Students controller:
class Students extends Controller {
function __construct() {
parent::__construct();
}
function index() {
$this->get_all_students();
}
function get_all_students() {
$s = new Student();
$data['students'] = $s->select('id, name, email')->get();
$this->load->view('students', $data);
}
function view($id) {
$s = new Student();
$s->get_by_id($id);
$s->groups->get();
$data['student'] = $s;
$this->load->view('student_view', $data);
}
}
I can get student's details like this in student_view:
Name: <?php echo $student->name; ?>
E-mail: <?php echo $student->email; ?>
Groups:
<?php foreach ($student->groups as $group) : ?>
<?php echo anchor("/groups/$group->id", $group->name) ?>
<?php endforeach; ?>
So, how can I list groups delimited by comma? I tried adding group names to an array in the controller and then just <?php echo implode(', ', $groups); ?> in the view. But this way I cannot make a link using group IDs.
<?php echo anchor("/groups/$group->id", $group->name) ?>
should become ( see the comma at the end of the line )
<?php echo anchor("/groups/$group->id", $group->name) ?> ,
or display user groups as a list :
<?php foreach ($student->groups as $group) : ?>
<?php echo anchor("/groups/$group->id", $group->name) ?>
<?php endforeach; ?>
should become
<ul>
<?php foreach ($student->groups as $group) : ?>
<li><?php echo anchor("/groups/$group->id", $group->name) ?></li>
<?php endforeach; ?>
</ul>
<?php
$first = true;
foreach ($student->groups as $group) :
if (! $first) echo ', ';
echo anchor("/groups/$group->id", $group->name);
$first = false;
endforeach;
?>

Resources