sampart / whiteoctoberpagerfantabundle Goto Github PK
View Code? Open in Web Editor NEWBundle to use Pagerfanta with Symfony
License: Other
Bundle to use Pagerfanta with Symfony
License: Other
E:\Github\symfony-standard>git submodule add http://github.com/whiteoctober/Pagerfanta.git vendor/pagerfanta
The following path is ignored by one of your .gitignore files:
vendor/pagerfanta
Use -f if you really want to add it.
So it seems this bundle is blocked in some or other way ?
Scrutinizer checks are not enabled on Scrutinizer, making the build useless. you should enable analysis tools
When i have 0 results, the pager shows page 0.. Using the DoctrineORMadapter as wel as the arrayadapter.
Am I using it wrong, or have i found a bug?:-)
HTML generated:
<nav>
<span class="disabled">Previous</span>
<span class="current">1</span>
<a href="/products/ebooks/0">0</a>
<span class="disabled">Next</span>
</nav>
PHP code used:
$em = $this->getDoctrine()->getManager();
$rep = $em->getRepository('GrenslandBundle:Product');
/* @var $rep \Doctrine\ORM\EntityRepository */
$qb = $rep->createQueryBuilder('u');
$qb->where('u.deleted = 0');
$filters = array();
if (($cat = $this->getRequest()->query->get('cat'))) {
$qb->where('u.categoryId = :CAT')->setParameter(':CAT', $cat);
$filters['Category'] = $em->find('GrenslandBundle:Product\Category', $cat)->getName();
}
$paginator = new \Pagerfanta\Pagerfanta(new \Pagerfanta\Adapter\DoctrineORMAdapter($qb));
try {
$paginator->setCurrentPage($page);
} catch (\Pagerfanta\Exception\NotValidCurrentPageException $e) {
return $this->redirect($this->generateUrl('firstclass_admin_product_index', array('page' => 1)));
}
Hello,
I'me used to use PagerFanta and this bundle on SF2 projects, and I know want to use it in Symfony 2.1.
I install it with composer adding this line in my composer.json file and update my project :
"white-october/pagerfanta-bundle": "dev-master"
The I try to display my pager (everything works fine in the controller, with the Pagerfanta\Pagerfanta class).
{{ pagerfanta(pager) }}
And I get this error :
The function "pagerfanta" does not exist in /path/to/my/template.html.twig at line 26
Do I get the installation wrong ? (I'm quite new to Composer)
I would like to override the default template, and custom it with a template.html.twig file in my root views folder
Can't find anything on internet about it...
An exception has been thrown during the rendering of a template
("Warning: array_merge(): Argument #2 is not an array in
[my_path]/symfony/vendor/bundles/WhiteOctober/PagerfantaBundle/Twig/PagerfantaExtension.php line 73")
in [my_view].html.twig at line 17.
in [my_view].html.twig at line 17 I have this code:
{{ pagerfanta(searchResults) }}
and in Pagerfanta at line 73:
$options['routeParams'] = array_merge($request->query->all(), $request->attributes->get('_route_params'));
unfortunately I haven't this var ('_route_params'). Might be you should tj set default option for 'get' method
for example:
$options['routeParams'] = array_merge($request->query->all(), $request->attributes->get('_route_params', array()));
Hey Pablo,
Could you please tag the latest version? We use 1.0.* in our composer.json?
Thnx :)
hi
in this situation :
{% if pager.haveToPaginate %}
{{ pagerfanta(pager, 'twitter_bootstrap3_translated', {'routeName': 'search_annonces_1'},{'routeParams' : { 'v': 'keyword' }}) }}
{% endif %}
we suppose inject keyword in pagination such a params route like this
/q=keyword&l=
but pagerfanta still generate route as
/q=&l=
this happen when routeName is passed as params into pagerfanta twig function
Hi all,
what is the bundle propose the results per page feature ?
i dont see it
maxPerPage: [1, 5, 10, 50, 100]
defaultMaxPerPage: 50
something like that, and the view for that ?
thx for replies
Forgive my ignorance, but what is the best way to use it with entity repository ?
Pass the pager fanta params to repository method, pass the adapter object or keep it in the controller and just get the query from repository.
Thanks for your advices.
Currently, Pagerfanta compiles the route to find the parameters needed to generate the url. This is both inefficient (getRouteCollection
triggers the routing loaders) and incompatible with both existing *I18nRoutingBundle (as they do some magic when generating the url and matching the route which is bypassed by this bundle).
In the master branch, Symfony now defines a _route_params
atribute in the Request containing the attributes used in the url. It would be a good idea to create a branch (or a tag) dedicated to the Symfony 2.0 compatibility and then to clean the code in the master branch for Symfony master.
How about to make a service as the wrapper class ?
native
$pagination = new Pagerfanta(new DoctrineORMAdapter($queryBuilder));
$pagination->setMaxPerPage($maxPerPage);
service
$pagination = $this->container->get('white_october_pagerfanta.doctrine_orm')
->setQueryBuilder($queryBuilder)
->getPagination()
;
$pagination->setMaxPerPage($maxPerPage);
or with setArguments
$pagination = $this->container->get('white_october_pagerfanta.doctrine_dbal')
->setArguments($queryBuilder, $countQueryBuilderModifier)
->getPagination()
;
$pagination->setMaxPerPage($maxPerPage);
and default service configuration
#app/config/config.yml;
white_october_pagerfanta:
default_adapter: doctrine_orm
using
$pagination = $this->container->get('white_october_pagerfanta.default')
->setArguments($queryBuilder)
->getPagination()
;
$pagination->setMaxPerPage($maxPerPage);
etc...
What is the simplest way to set Bootstrap 3 template as default and provide custom strings for next / previous?
If I use the OptionableView to pass in previous & next messages I loose the Bootstrap output.
This is follow up of #60.
I want create redirect to last available page when trying open non-existent page (OutOfRangeCurrentPageException
). Currently I've code like this
<?php
namespace Metal\ProjectBundle\Pagerfanta\EventListener;
use Pagerfanta\Exception\NotValidCurrentPageException;
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class HandleOutOfRangeCurrentPage implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* @param GetResponseForExceptionEvent $event
*/
public function onException(GetResponseForExceptionEvent $event)
{
$rootException = $exception = $event->getException();
do {
if ($exception instanceof OutOfRangeCurrentPageException) {
preg_match('/"(\d+)"$/', $exception->getMessage(), $matches); // this hack can be easy removed: create field "maxAvailablePage" in exception class
$maxPage = $matches[1];
$request = $event->getRequest();
$url = $this->router->generate(
$request->attributes->get('_route'),
array_merge(
$request->attributes->get('_route_params'),
$request->query->all(),
array('page' => $maxPage) // we have hardcoded page parameter name here
),
true
);
$event->setResponse(RedirectResponse::create($url, 301));
return;
}
if ($exception instanceof NotValidCurrentPageException) {
$event->setException(new NotFoundHttpException('Page Not Found', $rootException));
return;
}
} while ($exception = $exception->getPrevious()); // Twig wraps actual exception into his own
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
KernelEvents::EXCEPTION => array('onException', 512)
);
}
}
As you can see from code above, main problem is that we cann't dehardcode parameter for page name. Has anybody any suggestions for how to deal with it?
I think, that we can create method like Form::handleRequest
, something like $pagerfanta->handleRequest($request, 'nameOfPageParameter')
and then use this parameter on route generation.
v1.0.1 of this bundle has requirements of 1.0.* of library, and configures " TwitterBootstrap3View.php" as available view in v1.0.1 of bundle version.
But... 1.0.0 of lib doesn't have such class at all.
v1.0.1 version of this bundle should depend on >=1.0.1 of library not v1.0.*
And becouse of adding new features (bootstrap 3 support) even semantic versioning is not inline, as both versions should be 1.1.0
Update documentation to use composer instead of the "manual" installation.
When building the route in the Twig extension, you use the current request to get the route. this fails for subrequests (e.g. $this->forward()
or {% render %}
) and ESI requests (e.g. {% render with {}, {'standalone': true} %}
) as in this cases you don't use the master request containing the true route but an _internal
route that should not be available to the end-user but only to the proxy cache (or not at all if you don't use ESI).
There is no way to solve this for ESI as only the cache knows about the main request, and so giving the route explicitly is needed (which is already supported). However, this can be solved for subrequests. See the implementation I wrote for KnplabsPaginatorBundle
When using the twitter_bootstrap3_translated
template, an sr-only
class is added to the current page with the content (current)
. This content is not translated into the various languages.
Example:
When I use this in my Twig template:
{{ pagerfanta(pager, 'twitter_bootstrap3_translated') }}
I get this HTML (my app uses Dutch locale settings):
<ul class="pagination">
<li class="prev disabled"><span>← Vorige</span></li>
<li class="active"><span>1 <span class="sr-only">(current)</span></span></li>
<li><a href="/action/?page=2">2</a></li>
<li class="next"><a href="/action/?page=2">Volgende →</a></li>
</ul>
As you can see the (current)
bit is not translated.
I am getting this error:
An exception has been thrown during the rendering of a template ("Warning: array_merge(): Argument #2 is not an array in /usr/local/zend/apache2/htdocs/ck/vendor/bundles/WhiteOctober/PagerfantaBundle/Twig/PagerfantaExtension.php line 73") in CkAdminBundle:Widget:index.html.twig at line 16.
It appears the master version does not work with symfony 2.0.6
Should I download teh branch symfony2.0?
Hi, can't explain why but no page={number} parameter is added to the links to other pages. So that any page number clicked always returns you the first page. But the indicated number of items are selected. Any help would be appreciated.
Hi,
I have a problem with a query with count and sum and a group by.
$query->select(array('a', 'SUBSTRING(a.dateAppel, 1, 10) as groupby', 'COUNT(a) as nbappel', 'SUM(a.duration) as duree'))
->from('A:AB', 'a')
->where('a.dateAppel > \''.$filterAppelPoste->getDateStart().' 00:00:00\'')
->andWhere('a.dateAppel < \''.$filterAppelPoste->getDateEnd().' 23:59:59\'')
->groupBy('a.user')
->addGroupBy('groupby')
->add('orderBy', 'groupby ASC');
for debug i use
$result = $query->getResult();
\Doctrine\Common\Util\Debug::dump($result);
In this debug mode i find duree and nbappel with the right value.
my pagerAction
public function pagerAction($page , HttpFoundation\Request $request, $queryBuilder)
{
$pagerDoctrineAdapter = new Pagerfanta\Adapter\DoctrineORMAdapter($queryBuilder);
$pager = new Pagerfanta\Pagerfanta($pagerDoctrineAdapter);
$pager->setMaxPerPage($this->container->getParameter('lig_app.pager.max_per_page'));
try
{
$pager->setCurrentPage($page);
}
catch( Pagerfanta\Exception\NotValidCurrentPageException $e)
{
throw new HttpKernel\Exception\NotFoundHttpException();
}
return $pager;
}
and my view
{% for entity in pager.currentPageResults %}
<tr>
<td>{{ entity[0].user.username }}</td>
<td>{{ entity[0].destination }}</td>
<td>{{ entity.duree }}</td>
<td>{{ entity.nbappel }}</td>
{% set translationtype = 'view.asterix.appelposte.list.'~entity[0].typeappel|lower %}
<td>{{ translationtype|trans({}, 'LIGAsterixBundle') }}</td>
<td>{{ entity.groupby }}</td>
</tr>
{% endfor %}
In my view
"entity.duree" take the value on my first entity on group by
"entity.nbappel" always equal 1
I think Pager does not take the group by
Thx for your reply
See ya
When using the following code in the template, the output is only the previous and next link but disabled (as if there were only one page):
{{ pagerfanta(paginator, 'default') }}
I get the correct rendering when using this code to force counting the results:
{% set results = paginator.nbResults %}
{{ pagerfanta(paginator, 'default') }}
Btw, the CSS provided for the default view (in the comment) requires to enclose the view in a div with the pagerfanta
class, which is not documented anywhere.
In Polish translation file (Resources/translations/pagerfanta.pl.xliff), translations for next and previous are inversed.
Thanks.
I face this exception in my SF 2.0.14 install :
An exception has been thrown during the rendering of a template ("Warning: array_merge(): Argument #2 is not an array in /home/bruno/www/Bruno/Projects/Sf2/vendor/bundles/WhiteOctober/PagerfantaBundle/Twig/PagerfantaExtension.php line 77")
The problem is caused by $request->attributes->get('_route_params') as in my project it returns null.
As stated in the title, the DefaultTranslatedView expects a Pagerfanta\View\DefaultView hence the constructor fails as my DefaultView is not in the Pagerfanta namespace but mine.
I suggest that the DefaultTranslatedView should expect a ViewInterface class so a custom DefaultView is possible.
This is regarding #54
I propose to add ability to skip page=1 parameter (with adding "fallback" route) OR give ability to override default route generator (which is hardcoded now )
Let me know which one solution would be acceptable and I will create PR.
Similar to Issue #32 (but using the correct version of symfony).
I'm finding in Symfony 2.2 that there is a circumstance where $request->attributes->get('_route_params') does in fact return null. (and the merge error happens).
If rendering a fragment in twig, which calls a controller (and that controller ends up calling this extension), then the request attributes in that situation don't have a '_route_params' attribute set.
I'm guessing the break happened around this time:
http://symfony.com/blog/new-in-symfony-2-2-the-new-fragment-sub-framework
It think that the check for the 'internal' route is incorrect and an exception should be (legitimately) thrown.
The check should be against the 'strategy' option?
Is there a way to use pagerfanta and generate urls with get parameters? Like:
/my/nice/route?page=2
My controller by now is:
/**
* homepage
*
* @Route("/{_locale}/voices",
* name="blog_homepage",
* defaults={"page"=1},
* requirements={"page": "\d+"}
* )
* @Template
*
* @return array|\Symfony\Component\HttpFoundation\Response
*/
public function homepageAction()
{
.....
}
Class \Pagerfanta\View\TwitterBootstrap3View that used as a service in Resources/config/pagerfanta.xml:36 since 1.0.1 version () doesn't exist in Pagerfanta library versions lower that 1.0.1 but satisfied by version constraint 1.0.* in composer.json
Hi,
i have problem fetching data with Pagerfanta and composite keys
Here is specification of my table, I am wondering is it possible to use composite keys and pagerfanta?
Thnx
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Bundle\ApiBundle\Entity\Item2Term" table="item2_term" repository-class="Bundle\ApiBundle\Repository\Item2TermRepository">
<indexes>
<index name="item2_term_FI_1" columns="item2_id"/>
<index name="item2_term_FI_2" columns="term_id"/>
<index name="item2_term_FI_3" columns="sf_guard_user_id"/>
</indexes>
<id name="item2" association-key="true"/>
<id name="term" association-key="true"/>
<id name="sfGuardUser" association-key="true"/>
<field name="city" type="string" column="city" length="50" nullable="true"/>
<one-to-one field="sfGuardUser" target-entity="SfGuardUser">
<join-columns>
<join-column name="sf_guard_user_id" referenced-column-name="id"/>
</join-columns>
</one-to-one>
<one-to-one field="term" target-entity="Term">
<join-columns>
<join-column name="term_id" referenced-column-name="id"/>
</join-columns>
</one-to-one>
<one-to-one field="item2" target-entity="Item2">
<join-columns>
<join-column name="item2_id" referenced-column-name="id"/>
</join-columns>
</one-to-one>
</entity>
</doctrine-mapping>
I really hate it when readmes are not doing what they promise :-)
Add Pagerfanta and WhiteOctoberPagerfantaBundle to your vendors:
git submodule add http://github.com/whiteoctober/Pagerfanta.git vendor/pagerfanta
ok, let's go...
E:\Github\symfony-standard>git submodule add http://github.com/whiteoctober/Pagerfanta.git vendor/pagerfanta
fatal: Not a git repository (or any of the parent directories): .git
Why bundle developers always asume people are pulling symfony standard from git ?
Have you guys ever thought about the fact most people just download the release on symfony.com and there is not .git directory or anything like that ?
Why not simply creating a download that we can extract in vendors, and only have to set autoload and the kernel ?
It even doesn't work when you download the package from git here, as face it...
git submodule add http://github.com/whiteoctober/Pagerfanta.git vendor/pagerfanta
git submodule add http://github.com/whiteoctober/WhiteOctoberPagerfantaBundle.git vendor/bundles/WhiteOctober/PagerfantaBundle
This are two locations (vendor/pagerfanta and vendor/bundles/WhiteOctober/PagerfantaBundle), and when you download the package you only have a collection of files that should go into where ???
And it is more odd some bundles depend on this one, while you are not able to install it anyway.
You guys are not making it easy for symfony 2 users to use your bundle, that's for sure.
I have a problem displaying the records. After the initial configuration:
Item "isSelected" for "" does not exist in "WhiteOctoberAdminBundle::default/list.html.twig" at line 93
I am using WhiteOctoberPagerfantaBundle inside AdmingeneratorGeneratorBundle. When enabling the JMSI18nRouteBundle, it produces the following error:
Fatal error: Call to a member function compile() on a non-object in /Users/me/Projects/Web/htdocs/BikecityGuide/website/vendor/bundles/WhiteOctober/PagerfantaBundle/Twig/PagerfantaExtension.php on line 74
Must have something to do with the prefix of the I18n route, but I could not figure it out.
de__RG__Bcg_AdminBundle_User_list ANY /de/admin/user/
en__RG__Bcg_AdminBundle_User_delete ANY /admin/user/{pk}/delete
I am on branch symfony2.0.
is pagerfanta bundle ready for SF 2.1.1?
I want to add it to:
https://github.com/diaspar/symfony-sh
as an automatic download, but I am using composer and I dont see any instructions to install pagerfanta with composer in your README
Add view for Bootstrap 4.
Hi,
I can't change the previous message.. No problem with next it change perfectly but previous...
pagerfanta.view.test:
class: Pagerfanta\View\OptionableView
arguments:
- @pagerfanta.view.twitter_bootstrap
- { previous_message: ❰, next_message: ❱ }
public: false
tags: [{ name: pagerfanta.view, alias: test }]
Did i forget something ?
Hi,
I need to join non-related entities to perform some filtering and sorting.
I've done this by $qb->leftJoin('AcmeDemoBundle:Tag', 't', Expr\With, 'q.tag = tag.name')
.
However, this causes Cannot count query which selects two FROM components, cannot make distinction
error.
While googleing I've found that KnpPaginatorBundle has a solution for this.
Is there any way I could force similar behaviour with WhiteOctober/PagerFanta?
Hi,
We use PagerFantaBundle, and after a composer update we got this error : "Class 'Pagerfanta\View\TwitterBootstrap3View' not found"
It seems that PagerFantaBundle requires Pagerfanta 1.0.* but this version doest not include TwitterBootstrap3View.
Thanks !
Hi,
First, thank you all for this nice bundle.
I faced a problem of duplicate content with the pager. I'v got two routes about product listings because of SEO beliefs (example below).
product_home:
pattern: /products/
methods: GET
defaults:
_controller: ProductBundle:plop:index
page: 1
product_home_page:
pattern: /products/page-{page}
methods: GET
defaults:
_controller: ProductBundle:plop:index
page: 1
As you can guess /products/
and /products/page-1
display the same page and so, are seen as duplicate content.
I've solved it by passing the product_home
route as argument to the Pagerfanta Twig extension and use this to generate the route for first page.
Does it worth a pull request or is it too specific to integrate this possibility into the bundle ?
Let's say we have this url patterns :
/videos
/videos/page1
/videos/page2...
First, we need two routes, and we typically set a default page=1 for the first one.
But then, we have a SEO problem (duplicate content), the first two url match the same content. So, additionally to our two routes, we add a 301 redirection for "/videos/page1" to "/videos".
I really think this whole thing should be simpler, from Symfony routing system or the bundle, i don't know. Or maybe i'm missing something to do that ?
I would be really interested in having some feedbacks on how you manage your urls for this kind of common url patterns.
Hi
I saw all issues tracker for my issue but i couldn't get proper procedure to solve my problem.
Symfony version am using is 2.1.*
I added folder manually in my vendor
1. /vendor/pagerfanta => for pagerfanta folder got from https://github.com/whiteoctober/Pagerfanta
2. /vendor/bundles/WhiteOctober/PagerfantaBundle/WhiteOctoberPagerfantaBundle
file got(download) from https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle
i add two line manually in autoload.php
$loader->add('WhiteOctober\PagerfantaBundle', DIR.'/../vendor/bundles');
$loader->add('Pagerfanta', DIR.'/../vendor/pagerfanta/src');
Then i added namespace in AppKernel.php
$bundles = array(
//.....
new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
);
But am getting this
Fatal error: Class 'WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle' not found in /var/www/AceAdmin/app/AppKernel.php on line 23
error
So i need proper method(steps) to install WhiteOctoberPagerfantaBundle in symfony 2.1
If i get quick reply it will helpfull for me.
Thanks for ur help in advance
Sivavin
In PagerFantaExtension.php, line 73, the code says:
$options['routeParams'] = array_merge($request->query->all(), $request->attributes->get('_route_params'));
This will generate an exception when the second parameter to the array_merge() is not an array.
Replace with:
if (is_array($request->attributes->get('_route_params'))){
$options['routeParams'] = array_merge($request->query->all(), $request->attributes->get('_route_params'));
}else{
$options['routeParams'] = $request->query->all();
}
A new stable tag would come handy after all the deprecation removal patches commited in the last days. Thanks! :D
Hey!
Is there a plan for a new release of the bundle? It'd be great to have my project (based on Sylius) to use a stable version instead of dev-master :)
Hello,
I updated your bundle and Symfony (2.0.6) and now i encounter an error with PagerfantaExtension.php :
An exception has been thrown during the rendering of a template ("Warning: array_merge(): Argument #2 is not an array in ............../vendor/bundles/WhiteOctober/PagerfantaBundle/Twig/PagerfantaExtension.php line 73")
It seems $request->attributes->get('_route_params') at line 73 is not an array ... (I didn't debug more)
I did a quick and dirty patch like this :
if(is_array($request->attributes->get('_route_params')))
$options['routeParams'] = array_merge($request->query->all(), $request->attributes->get('_route_params'));
else
$options['routeParams'] = $request->query->all();
But I don't know consequences ...
Any ideas ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.