I have an array of items. Items are files paths. I have set up pagination but when I click on next it does not change. I want to display 1 pdf per page. Below is my code
class IndexController extends Zend_Controller_Action
{
public function init(){}
public function indexAction()
{
if($_SERVER['SERVER_NAME']=="portal-dev"){
$location = "/data/scan/invoice";
$listOfFiles = $this->readFiles($location);
$paginator = Zend_Paginator::factory($listOfFiles);
$paginator->setItemCountPerPage(1);
$this->view->paginator = $paginator;
}
}
public function readFiles($location){
$pattern="(\.pdf$)"; //valid image extensions
$thelist = array();
if ($handle = opendir($location)) {
while (false !== ($file = readdir($handle)))
{
if (eregi($pattern, $file)) //if this file is a valid image
{
$thelist[] = $file; //insert files into array
$max = count($thelist) - 1;
$max1 = count($thelist);
}
}
closedir($handle);
}
return $thelist;
}
}
index.phtml
<div id="main">
<?php if(!$this->paginator){
echo "No Files to process";
}else{
?>
<table>
<tr>
<td rowspan=2></td>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
<?php if (count($this->paginator)): ?>
<ul>
<?php foreach ($this->paginator as $item): ?>
<li><?php echo $item; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php echo $this->paginationControl($this->paginator,'Sliding','partial/my_pagination_control.phtml'); ?>
<?php }?>
</div>
pagination is found in directory partial
<?php if ($this->pageCount): ?>
<div
class="paginationControl">
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('page' => $this->previous)); ?>">
Previous </a> <span class="bar"> | </span>
<?php else: ?>
<span class="disabled"> Previous</span> <span class="bar"> | </span>
<?php endif; ?>
<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<a href="<?php echo $this->url(array('page' => $page)); ?>"> <?php echo $page; ?>
</a> <span class="bar"> | </span>
<?php else: ?>
<?php echo $page; ?>
<span class="bar"> | </span>
<?php endif; ?>
<?php endforeach; ?>
<!-- Next page link -->
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url(array('page' => $this->next)); ?>"> Next
</a>
<?php else: ?>
<span class="disabled">Next </span>
<?php endif; ?>
</div>
<?php endif; ?>
Try after setting the current page number in indexAction
$paginator->setCurrentPageNumber($this->_getParam('page'));
Like this
$paginator = Zend_Paginator::factory($listOfFiles);
$paginator->setItemCountPerPage(1);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$this->view->paginator = $paginator;
Related
on each products page I currently have displayed the products subcategory, but only one level deep. So if in categories I have Brother > MFC > B4564 > TN450.... and I am on the TN450's product page, down below it will only show BN4564 . I need it also show The mfc and the brother part. I am not sure how to do this.. any ideas? here is my current code.
.TPL file
<!-- Display product categories -->
<?php foreach ($catprod as $catp)
{
?><?php echo $catp['name']; ?> <?php
}`
controller .php file
$data['catprod'] = array();
$product_category = $this->model_catalog_product->getCategories($this->request->get['product_id']);
foreach ($product_category as $prodcat)
{
$category_info = $this->model_catalog_category->getCategory($prodcat['category_id']);
if ($category_info)
{
$data['catprod'][] = array('name' => $category_info['description'],'href' => $this->url->link('product/category', 'path=' . $category_info['category_id']));
}
}`
which version of opencart?
this should work for version 1:
open catalog/view/theme/default/template/module/category.tpl
remove its contents and insert:
<div class="box" id="categories-menu">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<ul class="box-category" id="box-category">
<?php foreach ($categories as $category) { ?>
<li>
<?php if ($category['category_id'] == $category_id) { ?>
<a href="<?php echo $category['href']; ?>" class="active list-group-item" ><?php echo $category['name']; ?></a>
<?php } else { ?>
<?php echo $category['name']; ?>
<?php } ?>
<?php if ($category['children']) { ?>
<ul class="submenu">
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
- <?php echo $child['name']; ?>
<?php } else { ?>
- <?php echo $child['name']; ?>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
Hey guys i want the sensor to be hidden by default and it show when i click on the particular node..and should be the same on page reload
Here is my code
<ul >
<?php if(isset($nodes)): ?>
<?php $count = 0; ?>
<?php foreach($nodes as $node) { ?>
<?php $node_id=$node['node_id']; ?>
<?php $sensors = config_sensor_model::getsensors($node_id); ?>
<?php $count++; ?>
<li onclick="menu(<?php echo $count; ?>)"><?php echo $node['node_name']; ?> </li>
<ul id="<?php echo "sub_".$count; ?>">
<?php foreach($sensors as $sensorlog) { ?>
<li> <?php echo $sensorlog->sensor_name; ?></li>
<?php } ?>
</ul>
<?php } ?>
<?php endif; ?>
</ul>
</div>
this is the javascript presently i am using
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
function menu(count)
{
$("#sub_"+count).toggle("fast");
}
</script>
As mentioned in my comment just use CSS to hide the node initially like this:
<style type="text/css">
.hidden { display: none; }
</style>
<ul>
if(isset($nodes)):
$count = 0;
foreach($nodes as $node) {
$node_id = $node['node_id'];
$sensors = config_sensor_model::getsensors($node_id);
$count++;
?>
<li onclick="menu(<?php echo $count; ?>)"><?php echo $node['node_name']; ?> </li>
<ul id="<?php echo "sub_".$count; ?>" class="hidden">
<?php foreach($sensors as $sensorlog) { ?>
<li> <?php echo $sensorlog->sensor_name; ?></li>
<?php } ?>
</ul>
<?php }
endif; ?>
</ul>
</div>
When menu is clicked, the display value will be toggled by Javascript.
Set style='display:none' for the <ul>
Here is my code:
<?php
$_rtl = Mage::getStoreConfig('custom_menu/general/rtl') + 0;
$_categories = $this->getStoreCategories();
if (is_object($_categories)) $_categories = $this->getStoreCategories()->getNodes();
?>
<div class="nav-container">
<div style="z-index:999;position:relative;top:-8px;left:979px;cursor:pointer;"><img src="<?php echo $this->getSkinUrl('images/Truck-Prince-text.png'); ?>" height="91" width="123" style="position:absolute;" onclick="location.href='<?php echo Mage::getUrl('checkout/cart'); ?>'"></div>
<div id="custommenu" class="<?php echo $_rtl ? ' rtl' : ''; ?>">
<?php if ($this->showHomeLink()) : ?>
<div class="menu">
<div class="parentMenu menu0">
<a href="<?php echo $this->getUrl('') ?>">
<span><?php echo $this->__('Home'); ?></span>
</a>
</div>
</div>
<?php endif ?>
<?php foreach ($_categories as $_category): ?>
<?php echo $this->drawCustomMenuItem($_category) ?>
<?php endforeach ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('nav-links-after')->toHtml() ?>
<div class="clearBoth"></div>
</div>
</div>
What I want to do is something like this but I don't know how to insert this in without causing errors. I basically want to change the existing url with the string replaced urls..
<?php // We must replace URLs on the fly to use landing pages and not break subcat navigation
$_category = str_replace('wild-bird-feed-supplies.html', 'landing-wild-bird-feed-supplies', $_category);
$_category = str_replace('lawn-garden-supplies.html', 'landing-lawn-garden-supplies', $_category);
$_category = str_replace('pet-food-supplies.html', 'landing-pet-food-supplies', $_category);
$_category = str_replace('animal-feed-supplies.html', 'landing-animal-feed-supplies', $_category); ?>
I finally was able to get it :) Here is what I did...
<?php
$_rtl = Mage::getStoreConfig('custom_menu/general/rtl') + 0;
$_categories = $this->getStoreCategories();
if (is_object($_categories)) $_categories = $this->getStoreCategories()->getNodes();
?>
<div class="nav-container">
<div style="z-index:999;position:relative;top:-8px;left:979px;cursor:pointer;"><img src="<?php echo $this->getSkinUrl('images/Truck-Prince-text.png'); ?>" height="91" width="123" style="position:absolute;" onclick="location.href='<?php echo Mage::getUrl('checkout/cart'); ?>'"></div>
<div id="custommenu" class="<?php echo $_rtl ? ' rtl' : ''; ?>">
<?php if ($this->showHomeLink()) : ?>
<div class="menu">
<div class="parentMenu menu0">
<a href="<?php echo $this->getUrl('') ?>">
<span><?php echo $this->__('Home'); ?></span>
</a>
</div>
</div>
<?php endif ?>
<?php foreach ($_categories as $_category): ?>
<?php $_category = $this->drawCustomMenuItem($_category) ?>
<?php // We must replace URLs on the fly to use landing pages and not break subcat navigation
$_category = str_replace('wild-bird-feed-supplies.html', 'landing-wild-bird-feed-supplies', $_category);
$_category = str_replace('lawn-garden-supplies.html', 'landing-lawn-garden-supplies', $_category);
$_category = str_replace('pet-food-supplies.html', 'landing-pet-food-supplies', $_category);
$_category = str_replace('animal-feed-supplies.html', 'landing-animal-feed-supplies', $_category); ?>
<?php echo $_category; ?>
<?php endforeach ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('nav-links-after')->toHtml() ?>
<div class="clearBoth"></div>
</div>
</div>
I wrote the code below to put together a customized menu of categories. Everything works fine, but would like the order of the categories were the same order as defined in the administrator panel where there drap and drop functionality.
<?php
$subCats = Mage::getModel('catalog/category')->load(76)->getChildren();
$dispositosCatIds = explode(',',$subCats);
?>
<ul class="menu">
<?php $controleNum = 0; ?>
<?php foreach($dispositosCatIds as $dispositoCatId): ?>
<?php $aparelhoCat = Mage::getModel('catalog/category')->load($dispositoCatId); ?>
<?php if($aparelhoCat->getIsActive()): ?>
<li class="<?php print $controleNum ? '' : 'submenu first'; ?>"><a class="drop" href="<?php echo $aparelhoCat->getUrl(); ?>"> <span><?php echo $aparelhoCat->getName(); ?></span></a> <!--Begin 6 column Item -->
<div class="dropdown_6columns">
<div class="inner"><span class="title"><?php echo $aparelhoCat->getName(); ?></span>
<div class="col_2">
<div class="col_2 firstcolumn"><img src="<?php echo $aparelhoCat->getImageUrl(); ?>" alt="<?php echo $aparelhoCat->getName(); ?>" /></div>
</div>
<div class="col_4" style="margin-bottom: 20px;">
<?php echo $aparelhoCat->getDescription(); ?>
</div>
<div class="col_2 categorias-super"><span class="title_col">Produtos para <?php echo $aparelhoCat->getName(); ?></span>
<?php $subSubCats = $aparelhoCat->getChildrenCategories();?>
<?php if (count($subSubCats) > 0): ?>
<?php //$controleNumLI = 0; ?>
<ul style="list-style: none; float: none !important;">
<?php foreach($subSubCats as $_subcategory): //Rodando entre as categorias de Um dispositivo ?>
<?php if($_subcategory->getIsActive()): ?>
<li class="level1 <?php //print $controleNumLI ? '' : 'first'; ?>"> <?php echo $_subcategory->getName(); ?></li>
<?php //$controleNumLI += 1; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
</div>
</li>
<?php $controleNum += 1; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
I tried to use other modes (based here) can do this, but I could not. The problem that the function returns getChildren() is a string with IDs in ascending order.
Some Ideas?
This is the code I use to display category in a dropdown box in the order of the admin... the key is setOrder('path','ASC')
$categories = array();
$_categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToFilter('is_active',array('eq'=>true))
->addAttributeToSelect('level')
->setOrder('path','ASC')
->addAttributeToSelect('name')->load();
foreach($_categories as $cat){
$level = $cat->getLevel() - 1;
$pad = str_repeat("----", ($level > 0) ? $level : 0);
$categories[] = array('value' => $cat->getEntityId(), 'label' => $pad . ' ' . $cat->getName());
}
print_r($categories);
You could do something like this: create array tree from array list
I got it:
$dispositovosCategoryId = 76;
$dispositovosCategoryIds = Mage::getModel('catalog/category')->getCollection()
->addFieldToFilter('parent_id', array('eq'=>$dispositovosCategoryId))
->addAttributeToFilter('is_active',array('eq'=>true))
->addAttributeToSelect('level')
->setOrder('position','ASC')
->addAttributeToSelect('name','url','image')
->load();
I'm trying to create a link based on a URL variable using only the last five digits of its respective line of XML data.
For example, if the XML link is http://events.stanford.edu/events/213/21389 how can I create this link a href="e/?i=21389?
Here's my page, XML and code:
<?php
// Build the XML file path, using URL variable $c (above)
$c = $_GET['c'];
$p ="http://events-prod.stanford.edu/xml/byCategory/";
$e = "/mobile.xml";
$file = "$p$c$e";
$xml = simplexml_load_file($file);
?>
<h1><?php echo $xml->title; ?></h1>
Home
</div><!-- /header -->
<div data-role="content">
<?php // Only display if there are events ?>
<?php if (isset($xml->Event->title)) { ?>
<ul data-role="listview">
<?php foreach($xml->Event as $event) { ?>
<li>
<a href="<?php echo $event->link; ?>">
<?php if ($event->Media->url != null) { ?>
<img src="<?php echo $event->Media->url;?>" alt="<?php echo $event->title;?> thumbnail" />
<?php } ?>
<h3><?php echo $event->title; ?></h3>
<p><strong><?php echo $event->beginDate; ?> at <?php echo $event->beginTime; ?></strong></p>
<p><?php echo $event->locationText; ?></p>
</a>
</li>
<?php } ?>
</ul>
<?php } else { ?>
<?php echo '<p>There is currently nothing scheduled for ', $xml->title, '.</p>';?>
<?php } ?>
I'm using short tags, because I think you'll agree it's easier now to read the code as oppose to before.
<?
$controller ="http://events-prod.stanford.edu/xml/byCategory/";
$category_id = $_GET['c'];
$category_id = 0;
$xml = "/mobile.xml";
$url = $controller . $category_id . $xml;
$xml_object = simplexml_load_file($url);
?>
<div>
<h1><?= $xml_object->title ?></h1>
Home
</div>
<div data-role="content">
<? if (!empty($xml_object->Event->title)): ?>
<ul data-role="listview">
<? foreach($xml_object->Event as $event): ?>
<li>
<?
$pattern = '/[0-9]+$/';
$matches = array();
preg_match($pattern, $event->link, $matches);
$my_link = 'e/?i=' . $matches[0];
?>
<a href="<?= $my_link ?>">
<? if (!empty($event->Media->url)): ?>
<img src="<?= $event->Media->url ?>" alt="<?= $event->title ?> thumbnail" />
<? endif; ?>
<h3><?= $event->title ?></h3>
<p><strong><?= $event->beginDate ?> at <?= $event->beginTime ?></strong></p>
<p><?= $event->locationText ?></p>
</a>
</li>
<? endforeach; ?>
</ul>
<? else: ?>
<? echo '<p>There is currently nothing scheduled for ', $xml_object->title, '.</p>'; ?>
<? endif; ?>
</div>