CodeIgniter - Undefined variable & Trying to get property of non-object - codeigniter

I'm trying to get data from API in my Controller and pass the data to the View. But it don't seem working and causing error:
Message:Undefined variable: data and
Message:Trying to get property of non-object
Both errors happen in my View.php, on the line when I call variable $data.
This is part of my controller related to data I want to get
$jdwl['jadwal'] = $this->bolalob->api('schedules/bydate|'.$start.'/'.$end.'/10');
$data['jadwal'] = $this->load->view('jadwal', $jdwl, TRUE);
$template['content'] = $this->load->view('jadwal',$data, TRUE);
$this->load->view('template', $template);
And this is my view
<div class="float-left first-column">
<div class="box box-shadow red round-top round-bottom">
<div class="title-box"><strong>JADWAL</strong> TV</div>
<ul class="text-center no-padding">
<?php if ($data->data == 'no data') { ?>
<li class="jadwal-tv"><strong>Belum ada jadwal</strong>
</li>
<?php } else { ?>
<?php foreach ($data->data as $key=>$row) { ?>
<?php if ($key == 0) { ?>
<li class="jadwal-tv"><strong><?php echo $row->team_1->name; ?></strong><br />VS<br /><strong><?php echo $row->team_2->name; ?></strong><br /><span><?php echo $row->television; ?> <?php echo date('d/m/y H:i', $row->pubdate); ?> WIB</span></li>
<?php } else { ?>
<li class="side-padding">
<strong><?php echo $row->team_1->name; ?></strong> vs <strong><?php echo $row->team_2->name; ?></strong>
<br />
<?php echo $row->television; ?> <?php echo date('d/m/y H:i', $row->pubdate); ?> WIB
</li>
<?php } ?>
<?php if ($key == 5) break; ?>
<?php } ?>
<?php } ?>
</ul>
</div>
</div>
The error happens to $data on line the 5 and 9. I've googled it and tried to use $data['jadwal'] instead of $data in my view but I didn't seem working too.
Anyone can help me with this?
Thanks :D

In your view no need to acess the $data array.
you can directly call your data key as a variable.
Ex:
In controller
$data['myVar']="Some string";
$this->load->view('viewName',$data);
In view
echo $myVar;

Try with the following view page..
<div class="float-left first-column">
<div class="box box-shadow red round-top round-bottom">
<div class="title-box"><strong>JADWAL</strong> TV</div>
<ul class="text-center no-padding">
<?php if (empty($jadwal)) { ?>
<li class="jadwal-tv"><strong>Belum ada jadwal</strong>
</li>
<?php } else { ?>
<?php foreach ($jadwal as $key => $row) { ?>
<?php if ($key == 0) { ?>
<li class="jadwal-tv"><strong><?php echo $row->team_1->name; ?></strong><br />VS<br /><strong><?php echo $row->team_2->name; ?></strong><br /><span><?php echo $row->television; ?> <?php echo date('d/m/y H:i', $row->pubdate); ?> WIB</span></li>
<?php } else { ?>
<li class="side-padding">
<strong><?php echo $row->team_1->name; ?></strong> vs <strong><?php echo $row->team_2->name; ?></strong>
<br />
<?php echo $row->television; ?> <?php echo date('d/m/y H:i', $row->pubdate); ?> WIB
</li>
<?php } ?>
<?php if ($key == 5) break; ?>
<?php } ?>
<?php } ?>
</ul>
</div>

Related

how to print specific value using while loop in codeigniter view page?

I want to print the value where country name is Canada. using foreach I have got the all value. In the while loop I restrict the value that which I want to print. are there any error in this line==> ins_country = "Canada"): ?>
<div style="width: 100%">
<?php foreach ($ins as $i) { ?>
<?php while ($i->ins_country = "Canada"): ?>
<div class="lop_div">
<h2> <?php echo $i->ins_country; ?></h2>
<?php echo $i->ins_name; ?><br>
</div>
<?php endwhile; ?>
<?php }
?>
</div>
Instead of while use if condition:
<?php foreach ($ins as $i) { ?>
<?php if ($i->ins_country = "Canada"): ?>
<div class="lop_div">
<h2> <?php echo $i->ins_country; ?></h2>
<?php echo $i->ins_name; ?><br>
</div>
<?php endif; ?>
<?php }
?>
<div style="width: 100%">
<?php foreach ($ins as $i) { ?>
<?php if ($i->ins_country == "Canada"){ ?>
<div class="lop_div">
<?php echo $i->ins_country;?>;
<?php echo $i->ins_name; ?><br>
</div>
<?php } ?>
<?php }
?>
</div>

How to create Custom Menu in magento with active and deactive class for category?

I need a custom categories menu in magento. and i want a active class on active category. when i click on category then that category should be add active class.
(i) First of all create your custom category from admin panel
(ii)Then pass the category id in getCategories() function in code
Try this code,it works for me.I hope this work for you.
<?php
$children = Mage::getModel('catalog/category')->getCategories(2);
?>
<div class="menusecond">
<ul id="second menu">
<?php
foreach ($children as $category) { ?>
<li class="mymenu">
<?php $catId = $category->getId(); ?>
<?php $cat = Mage::getModel('catalog/category')->load($catId); ?>
<a href="<?php echo $cat->getUrl(); ?>">
<?php echo $cat->getName(); ?>
</a>
</li>
<?php
}
?>
</ul>
</div>
I found the solution. we can identify current category by category getUrlKey.
<?php
$_helper = Mage::helper('catalog/category');
$_categories = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('is_active', 1) //only active categories
->addAttributeToFilter('include_in_menu', 1);
$currentCategory = Mage::registry('current_category') ;
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$rootCategory = Mage::getModel('catalog/category')->load($rootCategoryId);
$childIds = explode(',',$rootCategory->getChildren()); ?>
<div class="row">
<?php if (count($childIds) > 0): ?>
<ul>
<?php foreach($childIds as $_category):
$_category = Mage::getModel('catalog/category')->load($_category); ?>
<?php if ($_category->getIncludeInMenu()) { ?>
<?php $allsubchild = explode(',',$_category->getChildren());?>
<?php foreach($allsubchild as $_sub): ?>
<?php endforeach; ?>
<li class="<?php if (strpos($_SERVER['REQUEST_URI'], $_category->getUrlKey()) !== false){ echo "active";} ?>">
<?php echo $_category->getName() ?>
<?php } ?>
<ul>
<?php $ss = 0; foreach($allsubchild as $_sub):
$_subcategory = Mage::getModel('catalog/category')->load($_sub);
?>
<?php if ($_subcategory->getIncludeInMenu()) { ?>
<?php
$uri = $_category->getUrlKey();
$uri .= "/";
$uri .= $_subcategory->getUrlKey(); // echo $uri; ?>
<li class="<?php if($_subcategory->getChildrenCount()) { echo "has-dropdown1"; }?> <?php if (strpos($_SERVER['REQUEST_URI'], $uri) !== false){ echo "active";} ?>">
<?php echo $_subcategory->getName(); ?>
<?php $suren = explode(',',$_subcategory->getChildren());?>
<ul>
<?php
foreach($suren as $suren1){
$suren11 = Mage::getModel('catalog/category')->load($suren1);
$_suren1id = $suren11->getId();
$internet_count = Mage::getModel('catalog/category')->load($_suren1id)->getProductCount();
if ($internet_count > 0) {
if ($suren11->getIncludeInMenu()) { ?>
<?php
$uri1 = $uri;
$uri1 .= "/";
$uri1 .= $suren11->getUrlKey(); // echo $uri1; ?>
<li>
<a class="<?php if (strpos($_SERVER['REQUEST_URI'], $uri1) !== false){ echo "active";} ?>" href="<?php echo $suren11->getUrl(); ?>" title="<?php echo $suren11->getName(); ?>"><?php echo $suren11->getName(); ?></a>
</li>
<?php } ?>
<?php } ?>
<?php } ?>
</ul>
</li>
<?php }?>
<?php $ss++; endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
Goto app/design/frontend/rwd/default/template/page/html and open topmenu.phtml file. find this code <?php if($_menu): ?>
<nav id="nav">
<ol class="nav-primary">
<?php echo $_menu ?>
</ol>
</nav>
<?php endif ?>
this code will output you the categories in the form of top menu if you don't use any categories hide this code or else paste this code before or after this code.
<ul>
<li>HOME</li>
<li>ABOUT US</li>
<li>your_page_name</li>
<li>your_page_name</li>
</ul>

I want to display an option list for configurable attributes on product list page in magento

I want to display an option list for configurable attributes on product list page in magento, just like it appears on product view page for configurable products.I tried everything but nothing is working, looked for some similar topics but they are useless.Please help me resolve this issue.
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$sidebar=Mage::getStoreConfig('buyshoplayout/product_listing/sidebar');
$i=0;
$count=0;
$span=3;
$p_in_row=4;
$type=Mage::getStoreConfig('buyshoplayout/product_listing/product_listing_image_size');
if($type=='small')
{
$span=2;
$p_in_row=6;
}
?>
<?php if(!$_productCollection->count()): ?>
<div class="category-products aligncenter">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('buyshop_no_products')->toHtml() ?>
</div>
<?php else: ?>
<div class="category-products">
<?php echo $this->getToolbarHtml() ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php foreach ($_productCollection as $_product): ?>
<?php
$widthBig=258;
$heightBig=245;
$widthSmall=71;
$heightSmall=65;
$count++;
?>
<!--PRODUCT-->
<div class="row product-listing">
<?php echo Mage::helper('buyshopconfig')->getProductHtml($_product,$this,$widthBig,$heightBig,$span,false,true,true,false,$this->getPriceHtml($_product, true))?>
<div class="span6 product-detailes">
<h3 class="product-name bottom-line"><?php echo $this->stripTags($_product->getName(), null, true)?></h3>
<div class="bottom-line">
<?php echo $this->getPriceHtml($_product, true) ?>
<div class="product-review">
<?php echo Mage::helper('buyshopconfig')->getStars($_product)?>
</div>
</div>
<div class="bottom-line"><?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?></div>
<div class="product-buttons">
<?php echo Mage::helper('buyshopconfig')->addToCartLink($_product,$this,true)?>
<div class="add-to-links">
<ul>
<?php echo Mage::helper('buyshopconfig')->addWishCompLink($_product,$this,true)?>
</ul>
</div>
</div>
</div>
</div>
<!--PRODUCT EOF-->
<?php endforeach; ?>
<?php else: ?>
<?php // Grid Mode ?>
<?php if(!empty(Mage::registry('current_category')->name)):?>
<h2><?php echo Mage::registry('current_category')->name ?></h2>
<?php endif; ?>
<?php if($sidebar):?><div class="row big_with_description"><?php endif; ?>
<?php foreach ($_productCollection as $_product): ?>
<?php if(!$_product->isSaleable() && !Mage::getStoreConfig('cataloginventory/options/show_out_of_stock'))continue; ?>
<?php
$widthBig=258;
$heightBig=245;
$widthSmall=71;
$heightSmall=65;
$count++;
?>
<?php
if(!$sidebar)
{
$i++;
if($i==1)echo '<div class="row big_with_description">';
}
$price=$this->getPriceHtml($_product, true);
?>
<!--PRODUCT-->
<?php echo Mage::helper('buyshopconfig')->getProductHtml($_product,$this,$widthBig,$heightBig,$span,false,true,false,true,$price)?>
<?php echo Mage::helper('buyshopconfig')->getProductHover($_product,$this,$widthBig,$heightBig,$widthSmall,$heightSmall,$type,true,true,$price)?>
<!--PRODUCT EOF-->
<?php
if(!$sidebar)
{
if($i==$p_in_row || $count==count($_productCollection))
{
echo '</div>';
$i=0;
}
}
?>
<?php endforeach; ?>
<?php if($sidebar):?></div><?php endif; ?>
<?php endif; ?>
<?php echo $this->getToolbarHtml() ?>
</div>
<?php endif; ?>

Joomla 3.3.6 Category Blog - Subcategories before articles

I am trying to customise the category blog layout for only one category as follows:
this special category (ID 24) blog layout should display its list of
subcategories before the articles
the other categories will stick to the default layout: articles first and then
subcategories
I tried overriding blog.php:
<div class="blog<?php echo $this->pageclass_sfx; ?>" itemscope itemtype="http://schema.org/Blog">
<!-- SPECIAL CATEGORY - SUBCATEGORIES FIRST -->
<?php if ($this->category->id == 24 && !empty($this->children[$this->category->id]) && $this->maxLevel != 0) : ?>
<div class="cat-children">
<?php if ($this->params->get('show_category_heading_title_text', 1) == 1) : ?>
<h3> <?php echo JTEXT::_('JGLOBAL_SUBCATEGORIES'); ?> </h3>
<?php endif; ?>
<?php echo $this->loadTemplate('children'); ?> </div>
<?php endif; ?>
<?php
$introcount = (count($this->intro_items));
$counter = 0;
?>
<?php if (!empty($this->intro_items)) : ?>
<?php foreach ($this->intro_items as $key => &$item) : ?>
<?php $rowcount = ((int) $key % (int) $this->columns) + 1; ?>
<?php if ($rowcount == 1) : ?>
<?php $row = $counter / $this->columns; ?>
<div class="items-row cols-<?php echo (int) $this->columns; ?> <?php echo 'row-' . $row; ?> row-fluid clearfix">
<?php endif; ?>
<div class="span<?php echo round((12 / $this->columns)); ?>">
<div class="item column-<?php echo $rowcount; ?><?php echo $item->state == 0 ? ' system-unpublished' : null; ?>"
itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<?php
$this->item = & $item;
echo $this->loadTemplate('item');
?>
</div>
<!-- end item -->
<?php $counter++; ?>
</div><!-- end span -->
<?php if (($rowcount == $this->columns) or ($counter == $introcount)) : ?>
</div><!-- end row -->
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!empty($this->link_items)) : ?>
<div class="items-more">
<?php echo $this->loadTemplate('links'); ?>
</div>
<?php endif; ?>
<!-- OTHER CATEGORIES - SUBCATEGORIES LAST -->
<?php if (!empty($this->children[$this->category->id]) && $this->maxLevel != 0 && $this->category->id != 24) : ?>
<div class="cat-children">
<?php if ($this->params->get('show_category_heading_title_text', 1) == 1) : ?>
<h3> <?php echo JTEXT::_('JGLOBAL_SUBCATEGORIES'); ?> </h3>
<?php endif; ?>
<?php echo $this->loadTemplate('children'); ?> </div>
<?php endif; ?>
<?php if (($this->params->def('show_pagination', 1) == 1 || ($this->params->get('show_pagination') == 2)) && ($this->pagination->get('pages.total') > 1)) : ?>
<div class="pagination">
<?php if ($this->params->def('show_pagination_results', 1)) : ?>
<p class="counter pull-right"> <?php echo $this->pagination->getPagesCounter(); ?> </p>
<?php endif; ?>
<?php echo $this->pagination->getPagesLinks(); ?> </div>
<?php endif; ?>
It displays fine for the other categories, but when trying to view the special one, I get this:
{category title}
{description}
Notice: Undefined property: ContentViewCategory::$item in {joomla}\templates\wse\html\com_content\category\blog_children.php on line 63
Notice: Undefined property: ContentViewCategory::$item in {joomla}\templates\wse\html\com_content\category\blog_children.php on line 63
Notice: Trying to get property of non-object in {joomla}\templates\wse\html\com_content\category\blog_children.php on line 63
Fatal error: Call to a member function get() on a non-object in {joomla}\layouts\joomla\content\readmore.php on line 17
Sooo I must be missing something :) Could anyone please help?
Many thanks.
Use this debug your code link It seems to me like its complaining about $item on line 63 of blog_children. Use the link provided earlier to check all the valid properties of ContentViewCategory class

Extrafields Visibility. K2 Extension

So i have this code changed in ../html/com_k2/template/default/item.php:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<!-- Item extra fields -->
<div class="itemExtraFields">
<h3><?php echo JText::_('Additional Info:'); ?></h3>
<ul>
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<?php $user =& JFactory::getUser(); ?>
<?php if($extraField->name == "Price" && $user->get('Guest') ==1): ?>
<?php else: ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo ($extraField->type=='date')?JHTML::_('date', $extraField->value, JText::_('K2_DATE_FORMAT_LC')):$extraField->value; ?></span>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<div class="clr"></div>
</div>
<?php endif; ?>
What I'm trying to achieve is to hide the extrafield on Guest Viewer on the front-page, and that extrafield will only be visible to certain User groups. I already tried changing this line three times:
name == "Price" && $user->get('Guest')==1): ?>
name == "itemExtraFields" &&$user->get('Guest')
==1): ?>
name == "itemExtraFieldsValue"
&&$user->get('Guest') ==1): ?>
(I named my custom field as Price)
So i don't know if I'm missing something on the code or i got the itemFields name wrong. Any help would be appreciated a ton. I already asked in the k2 forum and joomla forum but no one is answering.
Try this code. It is working fine.
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<?php if($extraField->name === "Price" && $this->user->guest){}
else{ ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>
<?php }?>
<?php endforeach; ?>
I just added a strict comparison to the name and brackets for the if else condition. Also altered the way of checking guest user.

Resources