knp_paginator failed to open stream - symfony

After updating to Symfony 2.6, pages using kn._paginator no longer load:
An exception has been thrown during the rendering of a template
("Warning: file_get_contents(/Users/steve/dev/sites/virtual/newgt/
vendor/knplabs/knp-paginator-bundle/Knp/Bundle/PaginatorBundle/Resources/views
/Pagination/sliding.html.twig):
failed to open stream: No such file or directory") in
NewgtMediaBundle:Default:showSeriesSeason.html.twig at line 32
Config.yml ::
# KNP Paginator
knp_paginator:
page_range: 5 # default page range used in pagination control
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
template:
pagination: KnpPaginatorBundle:Pagination:sliding.html.twig # sliding pagination controls template
sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
The requested template:
/Users/steve/dev/sites/virtual/newgt/vendor/knplabs/knp-paginator-bundle/Knp/Bundle/PaginatorBundle/Resources/views/Pagination/sliding.html.twig
actually exists at:
/Users/steve/dev/sites/virtual/newgt/vendor/knplabs/knp-paginator-bundle/Resources/views/Pagination/sliding.html.twig
How do I tell my app where knp_paginator should look for the template?

Update config.yml
knp_paginator:
....
template:
# Following two lines were present before Symfony 2.6 upgrade.
# Commented out to load from default location.
# pagination: KnpPaginatorBundle:Pagination:sliding.html.twig # sliding pagination
# sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
Then
sudo rm -rf app/cache/prod
app/console cache:clear –env=prod
(same for –-env=dev)
both
http://mysite/app_dev.php/media/gallery/24223?page=5&count=82&number=1752&series=FIAGT&season=2009
and
http://mysite/media/gallery/24223?page=5&count=82&number=1752&series=FIAGT&season=2009
are working again.

Related

Symfony 4 - LiipImagine - How to clear cache?

on symfony 4 I use LiipImagineBundle for the display of my images.
But I noticed that there were cache problems.
My config is:
# See dos how to configure the bundle: https://symfony.com/doc/current/bundles/LiipImagineBundle/basic-usage.html
liip_imagine:
# valid drivers options include "gd" or "gmagick" or "imagick"
driver: "gd"
filter_sets:
cache: ~
# the name of the "filter set"
avatar_big:
# adjust the image quality to 75%
quality: 75
# list of transformations to apply (the "filters")
filters:
# create a thumbnail: set size to 120x90 and use the "outbound" mode
# to crop the image when the size ratio of the input differs
thumbnail: { size: [120, 120], mode: outbound }
My images are in :
public\images\avatar\
Is there a way to automatically clear the cache? I saw that there were orders to be made but I wonder if we can automate all that
If you mean to delete the cache images generated by your imagine filters, then LiipImagineBundle adds a command to Symfony console that does that:
php bin/console liip:imagine:cache:remove
Without any parameters, you will delete cache images for all paths and all filters.
You can use parameters to narrow the deletion to whatever filters and paths you want, like this:
php bin/console liip:imagine:cache:remove path1 path2 --filters=thumb1 --filters=thumb2
You have more information and examples here:
https://symfony.com/doc/current/bundles/LiipImagineBundle/commands.html#remove-cache

Generate url from parameters

I want to realize the following thing: in my parameters.yml I have uploads_url: http://test.site.com. It's a URL to Docker container with my images. Next, I have an entity with names of this pictures.
I want to generate URL in twig like this:
background-image: url({{ 'URL from parameters' + 'name of picture from `entity`' }})
At present time I have the second part of the previous expression (name of the picture). How can I generate the 1st part?
app/config/config.yml
# Twig Configuration
twig:
globals:
url: "%url%"
app/config/parameters.yml
parameters:
url: 'your_url'
official doc How to Inject Variables into all Templates (i.e. global Variables)
twig concatenate How to concatenate strings in twig

Unable to load knp_paginator bundle

I am getting the following error when I try to clear the cache in Symfony:
"Cannot import resource C:...\config.yml from "C:...\config_dev.yml"
(There is no extension able to load the configuration for
"knp_paginator")..."
And it goes on to say:
"Looked for namespace "knp_paginator", found "framework", "security",
"twig", etc etc"
It happens when I put the config settings suggested at https://github.com/KnpLabs/KnpPaginatorBundle into my config.yml file:
# Pagination
knp_paginator:
page_range: 5 # default page range used in pagination control
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
template:
pagination: KnpPaginatorBundle:Pagination:sliding.html.twig # sliding pagination controls template
sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
What am I doing wrong?
Discovered what it was:
I needed to add the bundle to the application kernel. In app/AppKernel.php, the function registerBundles() I needed to add:
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
And that fixed it.
for symfony 5 : add
Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class=> ['all' => true],
in config/bundles.php

"You cannot define a mapping item when in a sequence" when running phpunit in symfony

I'm getting the following errors when I try to run phpunit on my symfony project:
$ phpunit -c app
1) [...]\DefaultControllerTest::testIndex
Symfony\Component\Config\Exception\FileLoaderLoadException: Cannot import resource "/srv/http/typeform/app/config/config.yml" from "/srv/http/typeform/app/config/config_dev.yml".
/srv/http/typeform/vendor/symfony/src/Symfony/Component/Config/Loader/FileLoader.php:89
[...]
/srv/http/typeform/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:39
/srv/http/typeform/src/QuickyForm/PublicBundle/Tests/Controller/DefaultControllerTest.php:11
Caused by
Symfony\Component\Yaml\Exception\ParseException: You cannot define a mapping item when in a sequence in "\/srv\/http\/typeform\/app\/config\/config.yml"
/usr/share/pear/Symfony/Component/Yaml/Parser.php:116
[...]
/srv/http/typeform/app/bootstrap.php.cache:520
/srv/http/typeform/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:39
/srv/http/typeform/src/QuickyForm/PublicBundle/Tests/Controller/DefaultControllerTest.php:11
It seems that it crash when I call static::createClient();
Here's my config_test.yml
imports:
- { resource: config_dev.yml }
The errors you are getting suggest that the app is failing to parse your 'config.yml' because "You cannot define a mapping item when in a sequence".
This means that in a yml file when defining array values you cannot provide both mapping entries in the form "key: value" and sequence entries in the form "- item" - all values must be either one or the other form.
So, this is ok:
group:
key: value
key: value
This is also ok:
group:
- item
- item
This is not ok:
group:
key: value
- item
The errors suggest that there is an occurrence of the last form in your config.yml, although if this is the case it ought to cause problems running your app in the browser and not just under phpunit.
Additionally, to redbirdo's answer, you should be aware that you might need to use - under the required tag's items. For example:
UserLogin:
type: "object"
required:
- email
- password
security:
basicAuth: [] .......

Symfony 1.4 Doctrine MySQL Database table Views Module

With symfony 1.4 and doctrine you can generate frontend pages / modules with this command in your project directory: php symfony doctrine:generate-module --with-show --non-verbose-templates frontend tablename tableclassname
This works great with actual tables, however when I try to run this command on top of a MySQL DB View instead of a MySQL DB Table, I get this error: Cannot generate a module for a model without a primary key. The view inherits the primary key from the table it's reading off of, is my understanding.
Does anyone know a work around for this, that is still pretty easy to maintain with symfony? It would be amazing if I could use DB Views with the symfony framework. Let me know if you need any more details. In general no view seems to work no matter how complex or simple.
P.S. I tried editing the ./config/doctrine/schema.yml file to change the id column in the view to the primary key, which it is in the actual table & I still get the same error when trying to generate the frontend module in symfony.
tableName: v_tablename
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: true --> This used to be primary: false
default: '0'
notnull: true
autoincrement: false
*K I figured it out, but I can't post my answer until after 8 hours since I am a new user.
I was 1/2 way there when I edited the schema.yml file. If you are trying to generate a module off a view, and you have built your DB Model outside of symfony, say using MySQL Workbench, with doctrine you have to build your schema then build your model in symfony from your existing Database Structure like this:
1 - php symfony doctrine:build-schema (This generates the schema.yml file, etc.) However if you have views in your Database Schema, the primary keys aren't generated in the schema.yml file. Edit it manually and change the primary:false to primary:true accordingly where you need them.
2 - php symfony doctrine:build-model Once you do step 2 after adding your primary keys, you can then successfully generate your module
3 - php symfony doctrine:generate-module frontend module model
Minor correction... this will work, however I missed a step in between 2 & 3 that effects the form pages and broke down step 1.
1 - php symfony doctrine:build-schema (This generates the schema.yml file, etc.)
2 - Edit ./config/doctrine/schema.yml file. For your view definitions, change the primary:false to primary:true accordingly where you need them. I also noticed that in MySQL since boolean = tinyint(1), the schema.yml detects integer(1) and not boolean. You can also change your integer(1) datatypes to boolean where you need too.
tableName: v_tablename
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: false --> change to, primary: true
default: '0'
notnull: true
autoincrement: false
tableName: tablename
columns:
active:
type: integer(1) --> change to, type: boolean
fixed: false
unsigned: false
primary: false
default: '0'
notnull: true
autoincrement: false
3 - php symfony doctrine:build-model
4 - php symfony doctrine:build-forms
5 - php symfony doctrine:generate-module frontend module

Resources