Commit 83248460 by Julien Jorry

Update monolog conf + BO : user/presta/adherent admin simplify

parent f6557a8f
[Fri Nov 30 19:54:38.362098 2018] [authz_core:error] [pid 68481] [client 127.0.0.1:55323] AH01630: client denied by server configuration: /Users/julien/Desktop/DOUME/ledellin/public/
[Fri Nov 30 19:54:40.626560 2018] [authz_core:error] [pid 68481] [client 127.0.0.1:55323] AH01630: client denied by server configuration: /Users/julien/Desktop/DOUME/ledellin/public/favicon.ico, referer: http://doume.test/
......@@ -23,3 +23,27 @@ monolog:
handler: deprecation
max_level: info
channels: ["php"]
main_critical:
type: fingers_crossed
action_level: critical
handler: grouped_critical
grouped_critical:
type: group
members: [streamed_critical, buffered_critical]
streamed_critical:
type: rotating_file
max_files: 10
path: %kernel.logs_dir%/%kernel.environment%.critical.log
level: info
buffered_critical:
type: buffer
handler: swift_critical
swift_critical:
type: swift_mailer
from_email: debug@doume.org
to_email: [julien.jorry@gmail.com, stephan@gelberger.com]
# or list of recipients
# to_email: [julien.jorry@gmail.com, pascal.roos@gmail.com, ]
subject: "MLC : PHP Error !"
level: info
sonata_user:
# security_acl: true
security_acl: false
manager_type: orm # can be orm or mongodb
class:
user: App\Entity\User
group: App\Entity\Usergroup
profile:
default_avatar: 'images/admin/default_avatar.png' # Default avatar displayed if the user doesn't have one
admin: # Admin Classes
user:
class: App\Application\Sonata\UserBundle\Admin\UserAdmin
# controller: SonataAdminBundle:CRUD
translation: SonataUserBundle
impersonating:
route: sonata_admin_dashboard
route: sonata_admin_dashboard
sonata_block:
default_contexts: [sonata_page_bundle]
blocks:
......
......@@ -50,6 +50,14 @@ sonata_media:
formats:
small: { width: 100 , quality: 95}
big: { width: 500 , quality: 90}
faq:
providers:
- sonata.media.provider.image
- sonata.media.provider.file
formats:
small: { width: 100 , quality: 95}
big: { width: 500 , quality: 90}
cdn:
......
......@@ -5,7 +5,6 @@
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'
sonata.user.admin.user.class: 'App\Admin\UserAdmin'
services:
# default configuration for services in *this* file
......@@ -131,8 +130,8 @@ services:
tags:
- name: sonata.admin
manager_type: orm
group: "Document"
label: "Gérer"
group: "Contenu"
label: "Documents"
public: true
admin.rubrique.gerer:
......@@ -141,6 +140,16 @@ services:
tags:
- name: sonata.admin
manager_type: orm
group: "Rubrique"
label: "Gérer"
group: "Contenu"
label: "Rubriques"
public: true
admin.faq.gerer:
class: App\Admin\FaqAdmin
arguments: [~, App\Entity\Faq, ~]
tags:
- name: sonata.admin
manager_type: orm
group: "Contenu"
label: "FAQs"
public: true
......@@ -77,7 +77,7 @@ App\Entity\Prestataire:
siret: <text(10)>
geoloc (unique): '@geoloc*'
# user (unique): '@user<numberBetween(11,30)>'
typeprestataire: '@typepresta_prestataire'
typeprestataire: '@typepresta_prestataire*'
prestataire{22..32}:
raison: <text(10)>
responsable: <text(10)>
......@@ -87,7 +87,7 @@ App\Entity\Prestataire:
siret: <text(10)>
geoloc (unique): '@geoloc*'
# user (unique): '@user<numberBetween(11,30)>'
typeprestataire: '@typepresta_prestataire'
typeprestataire: '@typepresta_prestataire*'
groupeprestataires: ['@grppresta_*']
horaires: "<dayOfWeek()> de <time('H')>h à <time('H')>h"
......@@ -95,7 +95,7 @@ App\Entity\User:
usersuperadmin:
username: 'adminuser'
email: 'julien.jorry@gmail.com'
plainPassword: 'Fyeevuio22'
plainPassword: 'test'
enabled: true
groups: ['@usergroup_superadmin']
roles: ['ROLE_SUPER_ADMIN']
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -19,3 +19,15 @@
[Wed Jan 09 19:26:37.905339 2019] [php7:error] [pid 20965] [client 127.0.0.1:54948] PHP Fatal error: Method App\\Entity\\Groupe::__toString() must not throw an exception, caught TypeError: Return value of App\\Entity\\Groupe::__toString() must be of the type string, null returned in /Users/julien/Desktop/DOUME/ledellin/vendor/twig/twig/lib/Twig/Extension/Core.php on line 0, referer: http://www.doume.test/admin/app/groupe/list
[Wed Jan 09 19:44:38.386620 2019] [php7:error] [pid 20965] [client 127.0.0.1:59475] PHP Fatal error: Class App\\Form\\EntityToIdTransformer contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Symfony\\Component\\Form\\DataTransformerInterface::reverseTransform) in /Users/julien/Desktop/DOUME/ledellin/src/Form/EntityToIdTransformer.php on line 9, referer: http://www.doume.test/admin/app/groupe/list
[Wed Jan 09 20:05:19.917664 2019] [php7:error] [pid 25864] [client 127.0.0.1:64672] PHP Fatal error: Method App\\Entity\\Rubrique::__toString() must not throw an exception, caught TypeError: Return value of App\\Entity\\Rubrique::__toString() must be of the type string, null returned in /Users/julien/Desktop/DOUME/ledellin/vendor/twig/twig/lib/Twig/Extension/Core.php on line 0, referer: http://www.doume.test/admin/app/rubrique/list
[Mon Jan 14 16:43:14.544620 2019] [php7:error] [pid 40616] [client 127.0.0.1:54684] PHP Fatal error: Cannot declare class Sonata\\UserBundle\\Admin\\Model\\UserAdmin, because the name is already in use in /Users/julien/Desktop/DOUME/ledellin/src/Application/Sonata/UserBundle/Admin/UserAdmin.php on line 0
[Mon Jan 14 16:47:13.967624 2019] [php7:error] [pid 40568] [client 127.0.0.1:54748] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Model/UserAdmin.php on line 33, referer: http://www.doume.test/admin/user/list
[Mon Jan 14 16:47:14.377460 2019] [php7:error] [pid 40568] [client 127.0.0.1:54748] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Entity/UserAdmin.php on line 18, referer: http://www.doume.test/admin/user/list
[Mon Jan 14 16:47:16.036580 2019] [php7:error] [pid 40616] [client 127.0.0.1:54750] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Model/UserAdmin.php on line 33, referer: http://www.doume.test/admin/user/list
[Mon Jan 14 16:47:16.262028 2019] [php7:error] [pid 40616] [client 127.0.0.1:54750] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Entity/UserAdmin.php on line 18, referer: http://www.doume.test/admin/user/list
[Mon Jan 14 16:47:22.280013 2019] [php7:error] [pid 40569] [client 127.0.0.1:54753] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Model/UserAdmin.php on line 33
[Mon Jan 14 16:47:22.488889 2019] [php7:error] [pid 40569] [client 127.0.0.1:54753] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Entity/UserAdmin.php on line 18
[Mon Jan 14 16:47:40.051908 2019] [php7:error] [pid 40567] [client 127.0.0.1:54758] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Model/UserAdmin.php on line 33
[Mon Jan 14 16:47:40.482546 2019] [php7:error] [pid 40567] [client 127.0.0.1:54758] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Entity/UserAdmin.php on line 18
[Mon Jan 14 16:48:30.540076 2019] [php7:error] [pid 40571] [client 127.0.0.1:54761] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Model/UserAdmin.php on line 33
[Mon Jan 14 16:48:30.860332 2019] [php7:error] [pid 40571] [client 127.0.0.1:54761] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Entity/UserAdmin.php on line 18
[Mon Jan 14 16:50:00.697303 2019] [php7:error] [pid 40614] [client 127.0.0.1:54766] PHP Fatal error: Cannot declare class Sonata\\UserBundle\\Admin\\Model\\UserAdmin, because the name is already in use in /Users/julien/Desktop/DOUME/ledellin/src/Application/Sonata/UserBundle/Admin/UserAdmin.php on line 33
<?php
namespace App\Admin;
use App\Entity\User;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\MediaBundle\Form\Type\MediaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class FaqAdmin extends AbstractAdmin
{
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
$document = $this->getSubject();
$formMapper
->add('user', HiddenType::class, array(
'data' => $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser()->getId(),
'data_class' => null,
'entity_class' => User::class,
'em' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getEntityManager()
))
->add('name', TextType::class, array(
'label' => 'Titre :'
))
->add('text', CKEditorType::class, array(
'label' => 'Texte',
'required' => false,
))
->add('fichier', MediaType::class, array('provider' => 'sonata.media.provider.file', 'context' => 'faq'))
->add('image', MediaType::class, array('provider' => 'sonata.media.provider.image', 'context' => 'faq'))
;
}
/**
* {@inheritdoc}
*/
protected function configureListFields(ListMapper $listMapper)
{
unset($this->listModes['mosaic']);
$listMapper
->addIdentifier('name', null, array('label' => 'Titre'))
->addIdentifier('text', 'html', array('label' => 'Text'))
->addIdentifier('fichier', null, array('label' => 'Fichier'))
->addIdentifier('image', null, array('label' => 'Image'))
;
}
}
......@@ -29,6 +29,20 @@ class PrestataireAdmin extends UserAdmin
*/
protected function configureFormFields(FormMapper $formMapper): void
{
// get the current Image instance
$user = $this->getSubject();
$imageHelp = null;
if (!empty($user->getPrestataire()) && !empty($user->getPrestataire()->getMedia())) {
$image = $user->getPrestataire()->getMedia();
if ($image && ($webPath = $image->getWebPath())) {
// get the container so the full path to the image can be set
$container = $this->getConfigurationPool()->getContainer();
$fullPath = $container->get('request_stack')->getCurrentRequest()->getBasePath().'/'.$webPath;
// add a 'help' option containing the preview's img tag
$imageHelp = '<img src="'.$fullPath.'" class="admin-preview" />';
}
}
$formMapper
->tab('Prestataire')
->with('General', ['class' => 'col-md-6'])
......@@ -60,9 +74,10 @@ class PrestataireAdmin extends UserAdmin
))
->end()
->with('Image', ['class' => 'col-md-6'])
->add('media', MediaType::class, array(
->add('prestataire.media', MediaType::class, array(
'provider' => 'sonata.media.provider.image',
'context' => 'prestataire'
'context' => 'prestataire',
'help' => $imageHelp
))
->end()
->end()
......
......@@ -7,7 +7,7 @@ use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\UserBundle\Admin\Model\UserAdmin as SonataUserAdmin;
use App\Application\Sonata\UserBundle\Admin\UserAdmin as SonataUserAdmin;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormEvent;
......
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Application\Sonata\UserBundle\Admin;
use FOS\UserBundle\Model\UserManagerInterface;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelType;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\CoreBundle\Form\Type\DatePickerType;
use Sonata\UserBundle\Form\Type\SecurityRolesType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormTypeInterface;
use Sonata\UserBundle\Admin\Model\UserAdmin as BaseUserAdmin;
class UserAdmin extends BaseUserAdmin
{
/**
* {@inheritdoc}
*/
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper
->addIdentifier('username')
->add('email')
->add('groups')
->add('enabled', null, ['editable' => true])
->add('createdAt')
;
if ($this->isGranted('ROLE_ALLOWED_TO_SWITCH')) {
$listMapper
->add('impersonating', 'string', ['template' => '@SonataUser/Admin/Field/impersonating.html.twig'])
;
}
}
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $filterMapper): void
{
$filterMapper
->add('id')
->add('username')
->add('email')
->add('groups')
;
}
/**
* {@inheritdoc}
*/
protected function configureShowFields(ShowMapper $showMapper): void
{
$showMapper
->with('General')
->add('username')
->add('email')
->end()
->with('Groups')
->add('groups')
->end()
->with('Profile')
// ->add('dateOfBirth')
->add('firstname')
->add('lastname')
// ->add('website')
// ->add('biography')
// ->add('gender')
// ->add('locale')
// ->add('timezone')
->add('phone')
->end()
// ->with('Social')
// ->add('facebookUid')
// ->add('facebookName')
// ->add('twitterUid')
// ->add('twitterName')
// ->add('gplusUid')
// ->add('gplusName')
// ->end()
->with('Security')
->add('token')
->add('twoStepVerificationCode')
->end()
;
}
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper): void
{
// define group zoning
$formMapper
->tab('User')
->with('Profile', ['class' => 'col-md-6'])->end()
->with('General', ['class' => 'col-md-6'])->end()
// ->with('Social', ['class' => 'col-md-6'])->end()
->end()
->tab('Security')
->with('Groups', ['class' => 'col-md-8'])->end()
->with('Status', ['class' => 'col-md-4'])->end()
// ->with('Keys', ['class' => 'col-md-4'])->end()
// ->with('Roles', ['class' => 'col-md-12'])->end()
->end()
;
$now = new \DateTime();
$genderOptions = [
'choices' => call_user_func([$this->getUserManager()->getClass(), 'getGenderList']),
'required' => true,
'translation_domain' => $this->getTranslationDomain(),
];
// NEXT_MAJOR: Remove this when dropping support for SF 2.8
if (method_exists(FormTypeInterface::class, 'setDefaultOptions')) {
$genderOptions['choices_as_values'] = true;
}
// $formMapper->removeGroup('Social');
$formMapper
->tab('User')
->with('General')
->add('username')
->add('email')
->add('plainPassword', TextType::class, [
'required' => (!$this->getSubject() || null === $this->getSubject()->getId()),
])
->end()
->with('Profile')
// ->add('dateOfBirth', DatePickerType::class, [
// 'years' => range(1900, $now->format('Y')),
// 'dp_min_date' => '1-1-1900',
// 'dp_max_date' => $now->format('c'),
// 'required' => false,
// ])
->add('firstname', null, ['required' => false])
->add('lastname', null, ['required' => false])
// ->add('website', UrlType::class, ['required' => false])
// ->add('biography', TextType::class, ['required' => false])
// ->add('gender', ChoiceType::class, $genderOptions)
// ->add('locale', LocaleType::class, ['required' => false])
// ->add('timezone', TimezoneType::class, ['required' => false])
->add('phone', null, ['required' => false])
->end()
// ->with('Social')
// ->add('facebookUid', null, ['required' => false])
// ->add('facebookName', null, ['required' => false])
// ->add('twitterUid', null, ['required' => false])
// ->add('twitterName', null, ['required' => false])
// ->add('gplusUid', null, ['required' => false])
// ->add('gplusName', null, ['required' => false])
// ->end()
->end()
->tab('Security')
->with('Status')
->add('enabled', null, ['required' => false])
->end()
->with('Groups')
->add('groups', ModelType::class, [
'required' => false,
'expanded' => true,
'multiple' => true,
])
->end()
// ->with('Roles')
// ->add('realRoles', SecurityRolesType::class, [
// 'label' => 'form.label_roles',
// 'expanded' => true,
// 'multiple' => true,
// 'required' => false,
// ])
// ->end()
// ->with('Keys')
// ->add('token', null, ['required' => false])
// ->add('twoStepVerificationCode', null, ['required' => false])
// ->end()
->end()
;
}
}
......@@ -21,8 +21,28 @@ class IndexController extends AbstractController
// // no need to include %count% here; Symfony does that for you
// array('%name%' => $user->getName())
// );
return $this->render('index/index.html.twig', [
'controller_name' => 'IndexController',
return $this->render('index.html.twig', [
'news' => array(),
]);
}
/**
* @Route("/toto/{id}/{name}", name="toto")
*/
// public function index(TranslatorInterface $translator)
public function toto($id, $name)
{
// Exemple pour la traduction :
// $translated = $translator->trans('Symfony is great');
// $translator->transChoice(
// 'Hurry up %name%! There is one apple left.|There are %count% apples left.',
// 10,
// // no need to include %count% here; Symfony does that for you
// array('%name%' => $user->getName())
// );
return $this->render('index.html.twig', [
'toto' => 'toto',
'id' => $id
]);
}
}
......@@ -67,6 +67,7 @@ class Cotisation
private $moyen;
/**
* RECU ENVOYE ?
* @var bool
*
* @ORM\Column(name="recu", type="boolean", nullable=false)
......
......@@ -43,6 +43,13 @@ class Groupeprestataire
*/
protected $prestataires;
/**
* @var null|string (champ libre)
*
* @ORM\Column(name="horaires", type="string", length=255, nullable=true)
*/
private $horaires;
public function __construct()
{
$this->prestataires = new ArrayCollection();
......@@ -57,6 +64,25 @@ class Groupeprestataire
}
/**
* Get horaires
* @return string Horaires
*/
public function getHoraires(): ?string
{
return $this->horaires;
}
/**
* Set horaires
* @return $this
*/
public function setHoraires($horaires): self
{
$this->horaires = $horaires;
return $this;
}
/**
* @return Prestataire[]|ArrayCollection
*/
public function getPrestataires()
......
......@@ -8,14 +8,14 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190109183052 extends AbstractMigration
final class Version20190114180229 extends AbstractMigration
{
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE comptoir DROP user_id');
$this->addSql('ALTER TABLE groupeprestaire ADD horaires VARCHAR(255) DEFAULT NULL');
}
public function down(Schema $schema) : void
......@@ -23,6 +23,6 @@ final class Version20190109183052 extends AbstractMigration
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE comptoir ADD user_id INT NOT NULL');
$this->addSql('ALTER TABLE groupeprestaire DROP horaires');
}
}
<?php
namespace App\Security\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
class AdherentVoter extends Voter
{
protected function supports($attribute, $subject)
{
// replace with your own logic
// https://symfony.com/doc/current/security/voters.html
return in_array($attribute, ['POST_EDIT', 'POST_VIEW'])
&& $subject instanceof \App\Entity\BlogPost;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
return false;
}
// ... (check conditions and return true to grant permission) ...
switch ($attribute) {
case 'POST_EDIT':
// logic to determine if the user can EDIT
// return true or false
break;
case 'POST_VIEW':
// logic to determine if the user can VIEW
// return true or false
break;
}
return false;
}
}
<?php
namespace App\Security;
namespace App\Security\Voter;
use App\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
......@@ -12,6 +12,7 @@ class UserVoter extends Voter
const ADD = 'add';
const GET = 'get';
const EDIT = 'edit';
const LIST = 'list';
const REMOVE = 'remove';
private $decisionManager;
......@@ -66,6 +67,9 @@ class UserVoter extends Voter
private function canAdd(User $subject, User $user)
{
if ($this->decisionManager->decide($token, array('ROLE_ADHERENT'))) {
return false;
}
}
private function canGet(User $subject, User $user)
......
<?php
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
class AppExtension extends AbstractExtension
{
// public function getFilters(): array
// {
// return [
// // If your filter generates SAFE HTML, you should add a third
// // parameter: ['is_safe' => ['html']]
// // Reference: https://twig.symfony.com/doc/2.x/advanced.html#automatic-escaping
// new TwigFilter('toto', [$this, 'doSomething']),
// ];
// }
public function getFunctions(): array
{
return [
new TwigFunction('getLastNews', [$this, 'getLastNews']),
];
}
public function getLastNews($limit)
{
$db = $this->
$result= $db->findBy(array('enabled' => true), array('created' => 'DESC', 'limit' => $limit));
return $result;
}
}
{% extends 'base.html.twig' %}
{% block title %}Hello {{ controller_name }}!{% endblock %}
{% block title %}Hello !{% endblock %}
{% block body %}
<style>
......@@ -9,7 +9,7 @@
</style>
<div class="example-wrapper">
<h1>Helloa {{ controller_name }}! ✅</h1>
{# <h1>Helloa {{ getLastNews(5) }}! ✅</h1> #}
{# TRANSLATION :
{% trans %}Hello %name%{% endtrans %}
......@@ -21,7 +21,7 @@
This friendly message is coming from:
<ul>
<li>Your controller at <code><a href="{{ 'src/Controller/IndexController.php'|file_link(0) }}">src/Controller/IndexController.php</a></code></li>
<li>Your template at <code><a href="{{ 'templates/index/index.html.twig'|file_link(0) }}">templates/index/index.html.twig</a></code></li>
<li>Your template at <code><a href="{{ 'templates/index.html.twig'|file_link(0) }}">templates/index.html.twig</a></code></li>
</ul>
</div>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment