Skip to content

Instantly share code, notes, and snippets.

@andreybolonin
andreybolonin / ContactController.php
Created March 14, 2021 07:13
ContactController.php
<?php
$query = $this->getDoctrine()
->getRepository(Contact::class)
->createQueryBuilder('c');
$contacts = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1)/*page number*/ ,
$request->getSession()->get('items', $request->query->get('items', 100))
@andreybolonin
andreybolonin / pagination.html.twig
Created March 14, 2021 07:10
pagination.html.twig
<div class="navigation">
<div class="row">
<div class="col-1">
<p class="page-link" style="cursor: default!important;">
{{ 'Всего записей' }}:
{{ contacts.getTotalItemCount }}
</p>
</div>
<div class="col-1">
<div class="flex-column">
@andreybolonin
andreybolonin / pagination.yaml
Created March 14, 2021 07:01
config/packages/pagination.yaml
knp_paginator:
page_range: 10 # number of links showed in the pagination menu (e.g: you have 10 pages, a page_range of 3, on the 5th page you'll see links to page 4, 5, 6)
default_options:
page_name: page # page query parameter name
sort_field_name: sort # sort field query parameter name
sort_direction_name: direction # sort direction query parameter name
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements
filter_field_name: filterField # filter field query parameter name
filter_value_name: filterValue # filter value query parameter name
template:
@andreybolonin
andreybolonin / .gitignore
Created October 10, 2020 09:48
.gitignore
vendor/
.idea
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class NamespaceSymfony
@andreybolonin
andreybolonin / security.yaml
Created August 21, 2019 07:44
security.yaml
security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: username
firewalls:
dev:
@andreybolonin
andreybolonin / LocaleSubscriber.php
Created August 20, 2019 10:57
LocaleSubscriber.php
// src/EventSubscriber/LocaleSubscriber.php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class LocaleSubscriber implements EventSubscriberInterface
{
private $defaultLocale;
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="config/bootstrap.php"
>
<php>
<?php
namespace Tests\Controller;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\StringInput;
class AdminControllerTest extends WebTestCase