Error: Call to a member function getKeyName() - component for Joomla 2.5 - joomla

I got a fatal error with my component. Let's say the component name is com_shirts and this is my code
my code in administrator/component/com_shirts/controllers/code.php
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.controllerform');
class ShirtsControllerCode extends JControllerForm{
protected $view_list = 'codes';
}
my code in administrator/component/com_shirts/controllers/codes.php
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.controlleradmin');
class ShirtsControllerCodes extends JControllerAdmin{
protected $text_prefix = 'COM_SHIRTS';
function getModel($name='Code', $prefix='ShirtsModel', $config=array('ignore_request'=>TRUE)){
$model = parent::getModel($name, $prefix, $config);
return $model;
}
}
my code in administrator/component/com_shirts/models/code.php
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.modeladmin');
class ShirtsModelCode extends JModelAdmin{
function getTable($type='Code', $prefix='ShirtsTable', $config=array()){
return JTable::getInstance($type, $prefix, $config);
}
function getForm($data=array(), $loadData=TRUE){
$form = $this->loadForm();
return $form;
}
}
my code in administrator/component/com_shirts/models/codes.php
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
class ShirtsModelCodes extends JModelList{
function getItems(){
$items = parent::getItems();
foreach($items as &$item){
$item->url = 'index.php?option=com_shirts&task=code.edit&code_id='.$item->code_id;
$item->event_description = substr($item->code_desc, 0);
}
return $items;
}
function getListQuery(){
$query = parent::getListQuery();
$query->select('*');
$query->from('#__shirts_codes');
return $query;
}
}
my code in administrator/component/com_shirts/tables/code.php
<?php
defined('_JEXEC') or die;
class ShirtsTableCode extends JTable{
public function __construct(&$dbo){
parent::__construct('#__shirts_codes', 'code_id', $dbo);
}
}
my code in administrator/component/com_shirts/views/codes/view.html.php
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.view');
class ShirtsViewCodes extends JView{
protected $codes;
function display($tmpl=NULL){
$this->codes = $this->get('Items');
$this->toolbar();
parent::display($tmpl);
}
function toolbar(){
JToolBarHelper::title(JText::_('HEADER'));
JToolBarHelper::addNew('code.add');
JToolBarHelper::editList('code.edit');
JToolBarHelper::divider();
JToolBarHelper::publishList('codes.publish');
JToolBarHelper::unpublishList('codes.unpublish');
JToolBarHelper::divider();
JToolBarHelper::archiveList('codes.archive');
JToolBarHelper::trash('codes.trash');
JToolBarHelper::divider();
}
}
my code in administrator/component/com_shirts/views/codes/tmpl/default.php
<?php defined('_JEXEC') or die; ?>
<form action="index.php?option=com_shirts&view=codes" method="post" name="adminForm" id="adminForm">
<table class="adminlist">
<thead>
<tr>
<th style="width: 1%">
<input type="checkbox" name="checkall-toggle" value="" onclick="checkAll(this)" />
</th>
</tr>
</thead>
<tbody>
<?php foreach($this->codes as $i=>$code):
$url = 'index.php?option=com_shirts&view=code&task=code.edit&event_id='.$code->code_id;
?>
<tr class="row<?php echo $i%2; ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $code->code_id); ?>
</td>
<td class="center">
<a href="<?php echo $code->url; ?>">
<?php echo $this->escape($code->code); ?>
</a>
</td>
<td>
<a href="<?php echo $code->url; ?>">
<?php echo $this->escape($code->code_desc); ?>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
</form>
my code in administrator/component/com_shirts/views/code/tmpl/edit.php
<?php defined('_JEXEC') or die; ?>
<form
method="post"
name="adminForm"
class="form-validate"
action="index.php?option=com_shirts&code_id=<?php echo $this->code->code_id; ?>"
>
<div class="width-50 fltlft">
<fieldset class="adminform">
<ul class="adminformlist">
<?php foreach($this->form->getFieldset('required') as $field): ?>
<li>
<?php echo $field->label; ?>
<?php echo $field->input; ?>
</li>
<?php endforeach; ?>
</fieldset>
</div>
<div class="width-40 fltrt">
<fieldset class="adminform">
<ul class="adminformlist">
<?php foreach($this->form->getFieldset('optional') as $field): ?>
<li>
<?php echo $field->label; ?>
<?php echo $field->input; ?>
</li>
<?php endforeach; ?>
</ul>
</fieldset>
</div>
<input type="hidden" name="task" value="" />
<?php echo JHtml::_('form.token'); ?>
</form>
my code in administrator/component/com_shirts/views/code/view.html.php
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.view');
class ShirtsViewCode extends JView{
protected $code;
protected $form;
function display($tmpl=NULL){
$this->event = $this->get('Item');
$this->form = $this->get('Form');
$this->toolbar();
parent::display($tmpl);
}
function toolbar(){
if($this->code->code_id){
JToolBarHelper::title(JText::_('COM_SHIRTS_EDIT'));
}else{
JToolBarHelper::title(JText::_('COM_SHIRTS_ADD'));
}
JToolBarHelper::apply('code.apply', 'JTOOLBAR_APPLY');
JToolBarHelper::save('code.save', 'JTOOLBAR_SAVE');
JToolBarHelper::save2new('code.save', 'JTOOLBAR_SAVE_AND_NEW');
JToolBarHelper::divider();
JToolBarHelper::cancel('code.cancel');
}
}
and when I enter the component view, I get this error
"PHP Fatal error: Call to a member function getKeyName() on a non-object in /var/www/joomla/libraries/joomla/application/component/controllerform.php on line 393"
How do I fix this?

OK that was my bad i had mistake in manifest.xml everything is good now
In manifest there was no line
<folder>tables</folder>

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 do I grab only comments posted by current concrete5 logged in user?

This code displays all comments by all members. How can I make this only show comments that the current logged in user posted?
I know this is simple code but for the life of me I can not seem to get it.
The code listed below is the original code from the view.php file located in the guestbook block.
<?php $c = Page::getCurrentPage(); ?>
<h4 class="guestBook-title"><?php echo $controller->title?></h4>
<?php if($invalidIP) { ?>
<div class="ccm-error"><p><?php echo $invalidIP?></p></div>
<?php } ?>
<?php
$u = new User();
if (!$dateFormat) {
$dateFormat = t('M jS, Y');
}
$posts = $controller->getEntries();
$bp = $controller->getPermissionObject();
$dh = Loader::helper('date');
foreach($posts as $p) { ?>
<?php if($p['approved'] || $bp->canWrite()) { ?>
<div class="guestBook-entry<?php if ($c->getVersionObject()->getVersionAuthorUserName() == $u- >getUserName()) {?> authorPost <?php }?>">
<?php if($bp->canWrite()) { ?>
<div class="guestBook-manage-links">
<?php echo t('Edit')?> |
<?php echo t('Remove')?> |
<?php if($p['approved']) { ?>
<?php echo t('Un-Approve')?>
<?php } else { ?>
<?php echo t('Approve')?>
<?php } ?>
</div>
<?php } ?>
<div class="contentByLine">
<!---<?php echo t('Posted by')?>
<span class="userName">
<?php
if( intval($p['uID']) ){
$ui = UserInfo::getByID(intval($p['uID']));
if (is_object($ui)) {
echo $ui->getUserName();
}
}else echo $p['user_name'];
?>
</span>
<?php echo t('on')?>--->
<span class="contentDate">
<?php echo $dh->date($dateFormat,strtotime($p['entryDate']));?>
</span>
</div>
<?php echo nl2br($p['commentText'])?>
</div>
<?php } ?>
<?php }
if (isset($response)) { ?>
<?php echo $response?>
<?php } ?>
<?php if($controller->displayGuestBookForm) { ?>
<?php
if( $controller->authenticationRequired && !$u->isLoggedIn() ){ ?>
<div><?php echo t('You must be logged in for notes.')?> <?php echo t('Login')?> »</div>
<?php }else{ ?>
<a name="guestBookForm-<?php echo $controller->bID?>"></a>
<div id="guestBook-formBlock-<?php echo $controller->bID?>" class="guestBook-formBlock">
<!---<h5 class="guestBook-formBlock-title"><?php echo t('Leave a Reply')?></h5>--->
<form method="post" action="<?php echo $this->action('form_save_entry', '#guestBookForm-'.$controller->bID)?>">
<?php if(isset($Entry->entryID)) { ?>
<input type="hidden" name="entryID" value="<?php echo $Entry->entryID?>" />
<?php } ?>
<?php if(!$controller->authenticationRequired){ ?>
<label for="name"><?php echo t('Name')?>:</label><?php echo (isset($errors['name'])?"<span class=\"error\">".$errors['name']."</span>":"")?><br />
<input type="text" name="name" value="<?php echo $Entry->user_name ?>" /> <br />
<label for="email"><?php echo t('Email')?>:</label><?php echo (isset($errors['email'])?"<span class=\"error\">".$errors['email']."</span>":"")?><br />
<input type="email" name="email" value="<?php echo $Entry->user_email ?>" /> <span class="note">(<?php echo t('Your email will not be publicly displayed.')?>)</span> <br />
<?php } ?>
<?php echo (isset($errors['commentText'])?"<br /><span class=\"error\">".$errors['commentText']."</span>":"")?>
<textarea name="commentText"><?php echo $Entry->commentText ?></textarea><br />
<?php
if($controller->displayCaptcha) {
$captcha = Loader::helper('validation/captcha');
$captcha->label();
$captcha->showInput();
$captcha->display();
echo isset($errors['captcha'])?'<span class="error">' . $errors['captcha'] . '</span>':'';
}
?>
<br/><br/>
<input type="submit" name="Post Comment" value="<?php echo t('Save Note')?>" class="button"/>
</form>
</div>
<?php } ?>
Every $posts ($p) is an array. When you print the array you will notice the ID of the author is present in the array.
If you'd like to show only the comments of the logged in user, you should override the view.php and replace line number 16
<?php if($p['approved'] || $bp->canWrite()) { ?>
to
<?php if(($p['approved'] || $bp->canWrite()) && $u->getUserID() == $p['uID']) { ?>
When you've changed that line of code, a user should only see his/her comments and not the comment of someone else.

Magento - Controller to Ajax Estimate Shipping: Load Block and display phtml

I copied estimatePostAction and made estimateAjaxPostAction (overriding core - I did not hack the core). The controller action works as well (class Mage_Checkout_CartController).
Now I want to get/create a block for replacing shipping block after estimate shipping with ajax. I tried this:
public function estimateAjaxPostAction()
{
$country = (string) $this->getRequest()->getParam('country_id');
$postcode = (string) $this->getRequest()->getParam('estimate_postcode');
$city = (string) $this->getRequest()->getParam('estimate_city');
$regionId = (string) $this->getRequest()->getParam('region_id');
$region = (string) $this->getRequest()->getParam('region');
$this->_getQuote()->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setCollectShippingRates(true);
$this->_getQuote()->save();
//$this->_goBack();
$this->loadLayout();
$block = $this->getLayout()->createBlock('Mage_Checkout_Block_Cart_Shipping','checkout.cart.shipping.ajax',array('template' => 'checkout/cart/shipping.phtml'));
if($block) {
$response = array();
$response['shipping'] = $block->toHtml();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
}
}
The block checkout.cart.shipping.ajax was created. But toHtml() returns nothing.
My JSON returns:
{"shipping":""}
Why toHtml method doesn't work?
Edit: My block code (checkout/cart/shipping.phtml)
<?php /** #var $this Mage_Checkout_Block_Cart_Shipping */ ?>
<div class="row contem-shipping">
<div class="col-xs-10 shipping">
<div class="text-ship">
<h2><?php echo $this->__('Calcular o frete:') ?></h2>
<p><?php echo $this->__('Insira o CEP do endereço<br />no campo ao lado.') ?></p>
</div>
<div class="shipping-form">
<form action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>" method="post" id="shipping-zip-form">
<ul class="form-list">
<li class="no-display">
<div class="input-box">
<?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>
</div>
</li>
<?php if($this->getStateActive()): ?>
<li>
<label for="region_id"<?php if ($this->isStateProvinceRequired()) echo ' class="required"' ?>><?php if ($this->isStateProvinceRequired()) echo '<em>*</em>' ?><?php echo $this->__('State/Province') ?></label>
<div class="input-box">
<select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" style="display:none;"<?php echo ($this->isStateProvinceRequired() ? ' class="validate-select"' : '') ?>>
<option value=""><?php echo $this->__('Please select region, state or province') ?></option>
</select>
<script type="text/javascript">
//<![CDATA[
$('region_id').setAttribute('defaultValue', "<?php echo $this->getEstimateRegionId() ?>");
//]]>
</script>
<input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getEstimateRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
</div>
</li>
<?php endif; ?>
<?php if($this->getCityActive()): ?>
<li>
<label for="city"<?php if ($this->isCityRequired()) echo ' class="required"' ?>><?php if ($this->isCityRequired()) echo '<em>*</em>' ?><?php echo $this->__('City') ?></label>
<div class="input-box">
<input class="input-text<?php if ($this->isCityRequired()):?> required-entry<?php endif;?>" id="city" type="text" name="estimate_city" value="<?php echo $this->escapeHtml($this->getEstimateCity()) ?>" />
</div>
</li>
<?php endif; ?>
<li>
<div class="input-box">
<input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo $this->escapeHtml($this->getEstimatePostcode()) ?>" />
</div>
</li>
</ul>
<div class="buttons-set">
<button id="button-cep" style="width: 100px;" type="button" title="<?php echo $this->__('Get a Quote') ?>" onclick="calculaFreteAjax(jQuery('#postcode').val()); return false;" class="btn btn-2 btn-2a"><?php echo $this->__('Get a Quote') ?></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
//]]>
</script>
<?php $_shippingRateGroups = $this->getEstimateRates(); ?>
<?php if ($_shippingRateGroups): ?>
<form id="co-shipping-method-form" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>">
<dl class="sp-methods">
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
<dd>
<ul>
<?php foreach ($_rates as $_rate): ?>
<li<?php if ($_rate->getErrorMessage()) echo ' class="error-msg"';?>>
<?php if ($_rate->getErrorMessage()): ?>
<?php echo $this->escapeHtml($_rate->getErrorMessage()) ?>
<?php else: ?>
<input name="estimate_method" type="radio" value="<?php echo $this->escapeHtml($_rate->getCode()) ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio" />
<label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $this->escapeHtml($_rate->getMethodTitle()) ?>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</label>
<?php endif ?>
</li>
<?php endforeach; ?>
</ul>
</dd>
<?php endforeach; ?>
</dl>
</form>
<?php endif; ?>
<script type="text/javascript">
//<![CDATA[
var coShippingMethodForm = new VarienForm('shipping-zip-form');
var countriesWithOptionalZip = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;
coShippingMethodForm.submit = function () {
var country = $F('country');
var optionalZip = false;
for (i=0; i < countriesWithOptionalZip.length; i++) {
if (countriesWithOptionalZip[i] == country) {
optionalZip = true;
}
}
if (optionalZip) {
$('postcode').removeClassName('required-entry');
}
else {
$('postcode').addClassName('required-entry');
}
return VarienForm.prototype.submit.bind(coShippingMethodForm)();
}
//]]>
</script>
</div>
</div>
<div class="col-xs-6">
<?php
$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount(); //total items in cart
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
$subtotal = $totals["subtotal"]->getValue(); //Subtotal value
$grandtotal = $totals["grand_total"]->getValue(); //Grandtotal value
if(isset($totals['discount']) && $totals['discount']->getValue()) {
$discount = $totals['discount']->getValue(); //Discount value if applied
} else {
$discount = '';
}
$shipping = Mage::helper('checkout')->getQuote()->getShippingAddress()->getData();
$tax = $shipping["shipping_amount"];
/*if( $totals["tax"]->getValue()) {
$tax = $totals["tax"]->getValue(); //Tax value if present
} else {
$tax = '';
}*/
?>
<table class="totals-cart">
<tr>
<td class="total-tile">
Subtotal do pedido:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($subtotal, true, false); ?>
</td>
</tr>
<tr>
<td class="total-tile">
Frete:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($tax, true, false); ?>
</td>
</tr>
<?php if ($discount):?>
<tr>
<td class="total-tile">
Desconto:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($discount, true, false); ?>
</td>
</tr>
<?php endif;?>
</table>
</div>
</div>
<div class="row">
<div class="col-xs-16">
<div class="grand-total">
<p class="text">Total:</p>
<p class="price"><?php echo Mage::helper('core')->currency($grandtotal, true, false);?></p>
</div>
</div>
</div>
<script type="text/javascript">
function calculaFreteAjax(cep) {
jQuery('.contem-shipping .shipping').html('<span class="remove-frete" style="display: block; margin: 0 auto; width: 20px;" id="login-please-wait"><img src="http://sites.xpd.com.br/cpaps/skin/frontend/xpd/default/images/opc-ajax-loader.gif" class="v-middle" alt=""/></span>');
var param = {'country_id': 'BR','estimate_postcode': cep};
console.log(param);
jQuery.ajax({
type: "GET",
url: '<?php echo Mage::getBaseUrl().'checkout/cart/estimateAjaxPost/'; ?>', //My Custom Controller
data: param,
success: function(response) {
response = jQuery.parseJSON(response);
if(response.shipping) {
jQuery('.contem-shipping').parent().html(response.shipping);
}
else {
alert('Falha ao calcular o frete. Tente novamente.');
}
}
});
jQuery('#co-shipping-method-form dd input.radio').click(function(){
//I will submit the shipping method selected
});
}
</script>
Denis... I have modify code please check
public function estimateAjaxPostAction()
{
$country = (string) $this->getRequest()->getParam('country_id');
$postcode = (string) $this->getRequest()->getParam('estimate_postcode');
$city = (string) $this->getRequest()->getParam('estimate_city');
$regionId = (string) $this->getRequest()->getParam('region_id');
$region = (string) $this->getRequest()->getParam('region');
$this->_getQuote()->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setCollectShippingRates(true);
$this->_getQuote()->save();
$response = array();
$response['shipping']=$this->eastmatesajax();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
}
protected function eastmatesajax()
{
$layout=$this->getLayout();
$layout->getMessagesBlock()->setMessages(Mage::getSingleton('checkout/session')->getMessages(true),Mage::getSingleton('catalog/session')->getMessages(true));
$block = $this->getLayout()->createBlock('checkout/cart_shipping')->setTemplate( 'checkout/cart/shipping.phtml');
return $block->toHtml();
}
Updated block issue solved using $this->_getQuote()->collectTotals(); before $this->_getQuote()->save();

Implementing Lightbox in Magento

I already have an existing page which I'm trying to turn into a Magento website. One the pages I'm working on makes use of Lightbox. I tried including the lightbox file through Design in the CMS Page. Same for content but it didn't work there. Is there any way I can include the lightbox javascript from the previous website without having to touch the xml, html and php files? How do I make the lightbox work on the website?
You can always add a javascript file to the page's head by adding the following to the design tab of your CMS page (note that the path is relative to the root js directory). However, if you plan on using lightbox on multiple pages, this would not be the preferred method because you'd have to copy this into the design tab of every page you needed it on.
<reference name="head">
<action method="addJs"><js>custom/lightboxjs</js></action>
</reference>
View.PHTML
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<?php $config = Mage::getStoreConfig('mdloption/product-type-option'); ?>
<?php if($config['product-view-option'] !=2 && $config['product-view-option'] !=3): ?>
<?php $classnNum ='span9'?>
<?php else:?>
<?php $classnNum ='f-fix'?>
<?php endif; ?>
<?php if($config['product-view-option']==3):?>
<?php $classnNum2 = 'left-carousel'?>
<?php endif; ?>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<div class="product-view <?php echo $classnNum; ?>">
<!--<a class="prePage" href="<?php //echo $_SESSION['core']['last_url'];?>"><?php //echo $this->__('Return to Previous Page')?></a>-->
<!--Prev/Next Code Start-->
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();
$prev_url = $next_url = $url = $_product->getProductUrl();
if ($this->helper('catalog/data')->getCategory()) {
$category = $this->helper('catalog/data')->getCategory();
} else {
$_ccats = $this->helper('catalog/data')->getProduct()->getCategoryIds();
$category = Mage::getModel('catalog/category')->load($_ccats[0]);
}
$children = $category->getProductCollection();
$_count = is_array($children) ? count($children) : $children->count();
if ($_count) {
foreach ($children as $product) {
$plist[] = $product->getId();
}
$current_pid = $this->helper('catalog/data')->getProduct()->getId();
$curpos = array_search($current_pid, $plist);
$previd = isset($plist[$curpos+1])? $plist[$curpos+1] : $current_pid;
$product = Mage::getModel('catalog/product')->load($previd);
$prevpos = $curpos;
while (!$product->isVisibleInCatalog()) {
$prevpos += 1;
$nextid = isset($plist[$prevpos])? $plist[$prevpos] : $current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
}
$prev_url = $product->getProductUrl();
$nextid = isset($plist[$curpos-1])? $plist[$curpos-1] : $current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
$nextpos = $curpos;
while (!$product->isVisibleInCatalog()) {
$nextpos -= 1;
$nextid = isset($plist[$nextpos])? $plist[$nextpos] : $current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
}
$next_url = $product->getProductUrl();
}
?>
<!--Prev/Next Code End-->
<div class="product-essential">
<div class="product-img-box span6 <?php echo $classnNum2;?>"> <?php echo $this->getChildHtml('media') ?> </div>
<div class="productDetailBox span6">
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field_1" value="" />
</div>
<div class="product-shop">
<div class="product_left f-fix">
<div class="nextPre">
<!-- <a rel="tooltip" data-placement="left" title="<?php echo $this->__('No Products')?>" class="prod-prev disable" href="JavaScript:void(0);">Prev</a>
<a rel="tooltip" data-placement="right" title="<?php echo $this->__('No Products')?>" class="prod-next disable" href="JavaScript:void(0);">NEXT</a>-->
<?php if ($url <> $prev_url):?>
<a class="prod-next" rel="tooltip" data-placement="right" title="<?php echo $this->__('Volgende product')?>" href="<?php echo $prev_url; ?>"><i class="fa fa-angle-right"></i></a>
<?php endif; ?>
<?php if ($url <> $next_url):?>
<a rel="tooltip" data-placement="left" title="<?php echo $this->__('Vorige product')?>" class="prod-prev" href="<?php echo $next_url; ?>"><i class="fa fa-angle-left"></i></a>
<?php endif; ?>
</div>
<div class="product-name">
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
</div>
<div class="review"> <?php echo $this->getReviewsSummaryHtml($_product, false, true)?> </div>
<div class="stock_box">
<?php if ($_product->isAvailable()): ?>
<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('<i class="fa fa-check-circle"></i> Beschikbaar') ?></span></p>
<?php else: ?>
<p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('<i class="fa fa-times-circle"></i> Verkocht') ?></span></p>
<?php endif; ?>
</div>
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
<div class="pro-left">
<div class="add_to_cart">
<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php endif; ?>
<div class="price_box">
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getTierPriceHtml()?>
</div>
</div>
<?php endif; ?>
<?php echo $this->getChildHtml('other');?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
<?php endif;?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<div class="price_box">
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getTierPriceHtml()?>
</div>
<?php endif;?>
<div class="clear"></div>
</div>
<div class="f-fix">
<?php echo $this->getChildHtml('extrahint') ?>
<?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
<?php if ($this->canEmailToFriend()): ?>
<p class="email-friend"><a rel="tooltip" data-placement="top" title="<?php echo $this->__('Email to a Friend') ?>" href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>"><i class="fa fa-envelope"></i> <?php echo $this->__('Email to a Friend') ?></a></p>
<?php endif; ?>
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f74bbe87b978120"></script>
<!-- AddThis Button END -->
</div>
</div>
</div>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('static_links')->toHtml() ?>
</div>
</form>
</div>
<div class="product-collateral" id="tabs">
<?php echo $this->getChildHtml('info_tabs') ?>
</div>
</div>
</div>
<?php if($config['product-view-option'] !=2 && $config['product-view-option'] !=3): ?>
<div class="product_right span3">
<?php $config = Mage::getStoreConfig('mdloption/upsellsetting'); ?>
<?php if($config['upsellblocks']==1):?>
<?php echo $this->getChildHtml('upsell_products'); ?>
<?php elseif($config['upsellblocks']==2):?>
<?php if($_product->getUpsellProducts()): ?>
<?php echo $this->getChildHtml('upsell_products'); ?>
<?php else: ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('productBanner')->toHtml() ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('product_custom_block')->toHtml() ?>
<?php endif ?>
<?php elseif($config['upsellblocks']==3):?>
<?php echo $this->getChildHtml('upsell_products'); ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('productBanner')->toHtml() ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('product_custom_block')->toHtml() ?>
<?php endif;?>
<div class="staticSidebar">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('product-static-box')->toHtml() ?>
</div>
</div>
<?php endif; ?>
<?php //echo $this->getChildHtml('upsell_products'); ?>
<?php //echo $this->getChildHtml('related'); ?>
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("a[rel=example_group]").fancybox({
hideOnContentClick : true,
showNavArrows : false,
arrows : false,
showTitle : false,
scrolling : 'no',
'transitionIn' : 'none',
'transitionOut' : 'none',
'titlePosition' : 'over',
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';
}
});
});
</script>

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

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>

Resources