is there a way to customise the Yii CListView Pagination object to show
previous 1 of n pages next
rather then
previous 1,2,3 next ?
thanks
You cannot do this by simply passing parameters to the CLinkPager in order to modify its output. So, there is no more elegant method.
But you can very easily override the Pager class by extending CLinkPager and just change the createPageButtons()-Method in the following way:
Yii::import('web.widgets.pagers.CLinkPager');
class YourLinkPager extends CLinkPager{
/**
* Creates the page buttons.
* #return array a list of page buttons (in HTML code).
*/
protected function createPageButtons()
{
if(($pageCount=$this->getPageCount())<=1)
return array();
list($beginPage,$endPage)=$this->getPageRange();
$currentPage=$this->getCurrentPage(false); // currentPage is calculated in getPageRange()
$buttons=array();
// first page
$buttons[]=$this->createPageButton($this->firstPageLabel,0,self::CSS_FIRST_PAGE,$currentPage<=0,false);
// prev page
if(($page=$currentPage-1)<0)
$page=0;
$buttons[]=$this->createPageButton($this->prevPageLabel,$page,self::CSS_PREVIOUS_PAGE,$currentPage<=0,false);
/*
* !!! change has been made here !!!
*/
$buttons[]='<li>Page '.$this->getCurrentPage(false).' of '.$this->getPageCount().'</li>';
// next page
if(($page=$currentPage+1)>=$pageCount-1)
$page=$pageCount-1;
$buttons[]=$this->createPageButton($this->nextPageLabel,$page,self::CSS_NEXT_PAGE,$currentPage>=$pageCount-1,false);
// last page
$buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,self::CSS_LAST_PAGE,$currentPage>=$pageCount-1,false);
return $buttons;
}
}
http://www.yiiframework.com/forum/index.php/topic/5776-customise-the-clinkpager/
Related
Hello everybody I come towards you because I have small one concerns and I hope that to go to be able to you help me, I to create a shop with symfony but I have a small problem with the function "render ()" when I makes cross id in the controller kind by putting 3 or 4 for example it works but when I puts him dynamically that does not work
i share my code
my controller
/**
* #Route("/produits-views/{id}", name="product-views", methods="GET")
* #param int $id
* #return Response
*/
public function viewsProduct(int $id): Response {
$product = $this->getDoctrine()->getRepository(Product::class)->find($id);
return $this->render('inc/views-product.html.twig', [
'productViews' => $product
]);
}
and my function render
{{ render(controller('App\\Controller\\FrontController::viewsProduct',
{id: productViews.id}
)) }}
i include this on footer.html.twig and footer is include in base.html.twig
He takes out to me a message of this type
Variable "productViews" does not exist.
thank you for you helps !
change your action to let Symfony takes care of the fetching process:
/**
* #Route("/produits-views/{id}", name="product-views", methods="GET")
* #param Product $product
* #return Response
*/
public function viewsProductAction(Product $product): Response {
return $this->render('inc/views-product.html.twig', [
'productViews' => $product
]);
}
calling render with productViews.id in base.twig requires that in every view that extends this template need to have the productViews variable accessible which means that it have been provided to the view with render parameters.
you need to think about it, does all the views you have provide this variable like a user in the session if not remove it, you can alter the footer content from the view if you need to show the product according to each view using a dedicated Block for footer.
To make it easy, I have a GridView and I have to pass more parameters to the Ajax Call when I change page. The default parameters are:
current controller;
page number;
ajaxVar (default ajax) with the grid id as default;
I need to pass more parameters because the controller needs more parameters to recreate the correct grid.
On google I have found no answer.
Any advice?
Thanks!
Yii is extremly extendable, so you can create a Custom Pagination Widget. Firstly, have a look at this tutorial:
How to create a Custom Pagination Widget for Yii Framework
Here is example from our Project for createPageButton() function in extended Pagination:
/**
* Creates a page button.
* You may override this method to customize the page buttons.
*
* #param string $label the text label for the button
* #param integer $page the page number
* #param string $class the CSS class for the page button. This could be 'page', 'first', 'last', 'next' or 'previous'.
* #param boolean $hidden whether this page button is visible
* #param boolean $selected whether this page button is selected
* #return string the generated button
*/
protected function createPageButton($label, $page, $class, $hidden, $selected) {
if ($hidden || $selected)
$class .= ' ' . ($hidden ? 'disabled' : 'active');
return CHtml::tag('li', array(
'class' => $class
), CHtml::link($label, $this->createPageUrl($page).'&pageSize='.$this->pageSize));
}
Take a look at following code line:
CHtml::link($label, $this->createPageUrl($page).'&pageSize='.$this->pageSize)
Url Attribute is &pageSize=, and you can extend to any parameters you need with i.e. . '&myParameter=any_parameter'
This is definitely the way you can solve your problem and I hope it will help you. If you have any questions, feel free to ask.
I have a model for Product and Catalogue. They have many to many relationship, therefore I am using a pivot table called 'items'. I have a route:
/something/something/{catalogue}/{product}
I am passing the product model and catalogue model to the view, which outputs the product information and catalogue information - pretty straight forward. Now I need to have 2 buttons - 'next' and 'previous' to navigate through products in the catalogue.
So one way to do this, I thought I would create 2 methods on the Catalogue model that would accept the current product model and return next / prev model based on ID:
public function prevProduct($product){
$prevProdId = Product::where('id', '<', $product->id)->max('id');
return Product::find($prevProdId);
}
public function nextProduct($product){
$nextProdId = Product::where('id', '>', $product->id)->min('id');
return Product::find($nextProdId);
}
Now this works fine, but as you can see, it retrieves the next product and previous product from the Product table in the database, not the catalogue.
To get all the products in the catalogue, can be done like so: $this->items (on Catalogue model) or $catalogue->items (from view).
I somehow need to get next / prev items from the Catalogue, but can't figure out how. Any suggestions would be much appreciated.
You can filter Collection, like this:
$next = $item->id + 1;
$catalogue->filter(function($item) use ($next ) {
return $item->id == $next;
})->first();
I use global method added to Collection class:
/**
* Returns first object from collection which meets attribute criteria
*
* #param string $attributeName name of attribute we are looking for
* #param string $attributeValue value of attribute that have to be met
* #return \Illuminate\Database\Eloquent\Collection
*/
public function findByAttribute($attributeName, $attributeValue)
{
return $this->filter(function($item) use ($attributeName, $attributeValue) {
return $item->{$attributeName} == $attributeValue;
})->first();
}
In this case I would use this method this way:
$catalogue->items->findByAttribute('id', $next);
In both examples I assume You have $item object to reffer to.
You can use Pagination
Catalogue::first()->items()->paginate(1);
Actually, it was much simpler. This did the trick:
$nextProdId = $this->items()->where('product_id', '>', $product->id)->min('product_id');
return Product::find($nextProdId);
I had to add () after 'items' to enable 'where' clause and make it searchable basically.
I want to create entire website based on 2 columns only. So I want to remove all one column and 3 column layouts.
I want to remove these options even from the administration area.
How to do this?
You need to rewrite (whether by using app/code/local or by using a module) Mage_Page_Model_Source_Layout::getOptions() like this:
/**
* Retrieve page layout options
*
* #return array
*/
public function getOptions()
{
// Array of layout codes that are allowed
$allowedLayoutCodes = array('empty', 'two_columns_left', 'two_columns_right');
if ($this->_options === null) {
$this->_options = array();
foreach (Mage::getSingleton('page/config')->getPageLayouts() as $layout) {
// If layoutCode in foreach loop is allowed
if(in_array($layout->getCode(), $allowedLayoutCodes)) {
$this->_options[$layout->getCode()] = $layout->getLabel();
if ($layout->getIsDefault()) {
$this->_defaultValue = $layout->getCode();
}
}
}
}
return $this->_options;
}
For Remove Layout option from administrative area, you have to edit core file. For this pls comment required layouts in app\code\core\Mage\Page\etc\config.xml.
Please Make sure that you have removed all removed layout references from your frontend theme.
Whenever a user searches, I get this error:
2012-06-26 11:05:21.671 [NOTICE] [208.69.120.120:48175-0#hostname] [STDERR] PHP Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::getEntityTablePrefix() in /chroot/home/SITENAME/DOMAIN.COM/html/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php on line 505
And instead of the user's results appearing, they get a blank white page- no error on their end, no UI, just white. This was the first issue I noticed, but on the same day the following issues started coming up:
White Search Results
Sub-category product count for all sub-categories in layered nav is showing 0.
Some customers can not view orders from their front-end UI when logged in.
Our order export script is returning blank fields (1.7mb instead of 4.3).
Our "Made-in-the-usa" and "best sellers" pages are returning more products than they should.
Now, I know these are all incorrect because if I reindex the entire site, for some period while it is processing the index, all of the above works. However, when the index is complete, it all breaks again. The same day this happened we had an error page appear that stated one of the tables had broken and should be repaired. We ran PHPMyAdmin's repair and optimize functions on all tables and it fixed that error- but all of these are still broken.
Any ideas at all? Any ideas of what could be tried to fix this? I cant find this error anywhere- and the guys over at Nexcess haven't been able to find anything for this, either.
Thank you for your time.
As per the comments above, Magento's telling you that it's trying to call the method getEntityTablePrefix on an object whose classes don't have that method defined. Specifically in this method
#File: app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php
public function getBackendTable()
{
if ($this->_dataTable === null) {
if ($this->isStatic()) {
$this->_dataTable = $this->getEntityType()->getValueTablePrefix();
} else {
$backendTable = trim($this->_getData('backend_table'));
if (empty($backendTable)) {
$entityTable = array($this->getEntity()->getEntityTablePrefix(), $this->getBackendType());
$backendTable = $this->getResource()->getTable($entityTable);
}
$this->_dataTable = $backendTable;
}
}
return $this->_dataTable;
}
Given this happens from the following class
Mage_Catalog_Model_Resource_Product_Flat
It says to me that you have an extension and/or customization done that assumes you're not using the flat catalog data tables and wasn't coded to work with the flat table.
Dropping in a debugging call like this
if(!is_callable(array($this->getEntity()),'getEntityTablePrefix'))
{
mageDebugBacktrace();
//debug_print_backtrace();
exit;
}
right before the offending call (in a local code pool override, of course), will print out a call-stack that should point the offending code.
The seems that problem is in Mage_CatalogSearch_Model_Resource_Search_Collection::_getSearchEntityIdsSql that is not compatible with using the product flat index.
You can rewrite class Mage_CatalogSearch_Model_Resource_Search_Collection and do two little modifications.
1) Add new function _getSearchEntityIdsSqlUsingFlatIndex to rewrited class. This new function (I hope) does exactly the same thing as original _getSearchEntityIdsSql, but with using the product flat index.
2) Modify function _getSearchEntityIdsSql so that it calls new _getSearchEntityIdsSqlUsingFlatIndex if the catalog product flat index is enabled and built.
See source code:
class VENDOR_MODULE_Model_PATHTOREWRITECLASS extends Mage_CatalogSearch_Model_Resource_Search_Collection {
/**
* Retrieve SQL for search entities using product flat index.
*
* #param $query
* #return Varien_Db_Select
*/
protected function _getSearchEntityIdsSqlUsingFlatIndex($query)
{
/* #var $coreHelper Mage_Core_Model_Resource_Helper_Abstract */
$coreHelper = Mage::getResourceHelper('core');
$likeOptions = array('position' => 'any');
$flatTableName = $this->getTable('catalog/product_flat').'_'.$this->getStoreId();
/** #var Varien_Db_Select $select */
$select = $this->getConnection()
->select()
->from($flatTableName, array('entity_id'));
foreach ($this->_getAttributesCollection() as $attribute) {
/** #var Mage_Catalog_Model_Entity_Attribute $attribute */
if ($this->_isAttributeTextAndSearchable($attribute)) {
$attributeCode = $attribute->getAttributeCode();
$dbFieldName = in_array($attribute->getFrontendInput(), array('select', 'multiselect'))
? $attributeCode.'_value'
: $attributeCode;
if ($this->getConnection()->tableColumnExists($flatTableName, $dbFieldName)) {
$select->where($coreHelper->getCILike($dbFieldName, $this->_searchQuery, $likeOptions));
} else {
Mage::log(__METHOD__.": Attribute '$attributeCode' is missing in flat index.", Zend_Log::NOTICE);
}
}
}
return $select;
}
/**
* Retrieve SQL for search entities
*
* #param unknown_type $query
* #return string
*/
protected function _getSearchEntityIdsSql($query)
{
// HACK - make compatibility with flat index
/** #var Mage_Catalog_Helper_Product_Flat $flatHelper */
$flatHelper = Mage::helper('catalog/product_flat');
if ($this->getStoreId() > 0
&& $flatHelper->isEnabled($this->getStoreId())
&& $flatHelper->isBuilt($this->getStoreId())
) {
return $this->_getSearchEntityIdsSqlUsingFlatIndex($query);
}
// END HACK
return parent::_getSearchEntityIdsSql($query);
}
}