Symfony 1.4 Doctrine MySQL Database table Views Module - symfony-1.4

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

Related

Trying to export dynamodb table variables from a serverless stack fails with intrinsic function !Ref

I have a working stack built with servereless framework which includes a dynamodb table (stack was already deployed successfully). I am trying to export the dynamo table's variables (name and arn basically) so these could be used in another stack I have deployed.
To achieve this I have the following:
in serverless.yml:
resources:
Resources:
AqDataTable: ${file(resources/AqDataTable.yml):AqDataTable}
Outputs:
AqDataTableName: ${file(resources/AqDataTable.yml):Outputs.AqDataTableName}
AqDataTableArn: ${file(resources/AqDataTable.yml):Outputs.AqDataTableArn}
(...)
custom:
AqDataTable:
name: !Ref AqDataTable
arn: !GetAtt AqDataTable.Arn
stream_arn: !GetAtt AqDataTable.StreamArn
in resources/AqDataTable.yml:
Outputs:
AqDataTableName:
Value: ${self:custom.AqDataTable.name}
Export:
Name: ${self:custom.AqDataTable.name}-Name
AqDataTableArn:
Value: ${self:custom.AqDataTable.arn}
Export:
Name: ${self:custom.AqDataTable.name}-Arn
When trying to deploy I get the following error:
Serverless Error ---------------------------------------
Trying to populate non string value into a string for variable ${self:custom.AqDataTable.name}. Please make sure the value of the property is a string.
The way I worked around this is by replacing AqDataTable.name value in the serverless.yml custom section from !Ref AqDataTable to a "harder-coded" value: AqDataTable-${self:provider.stage} but obviously this is a bad practice which I would like to avoid.
I'd appreciate any inputs on why this stack format invalidates the !Ref intrinsic function, or better ways to achieve what I am after here.
Many thanks!
In case anyone ever faces this issue:
After going over the docs one more time, apparently what I initially tried to do is not possible. According to CF docs:
For outputs, the value of the Name property of an Export can't use Ref
or GetAtt functions that depend on a resource.
Similarly, the ImportValue function can't include Ref or GetAtt
functions that depend on a resource.

Symfony FOSRestBundle enableMaxDepthChecks default to true

Is it possible to set the default value for enableMaxDepthChecks to true?
Currently I have to add the following annotation to every route:
#View(serializerEnableMaxDepthChecks=true)
Is there a way to set this in the config or elsewhere to be the default?
Place this into your config.yml
jms_serializer:
default_context:
serialization:
enable_max_depth_checks: true
BUT! After making these changes, the parameter serializerEnableMaxDepthChecks becomes non-working, so you can't set it to false , and I don't know why...

NelmioApiDoc - Hide documentation section by default

By default, ApiDoc lists out all operations for each API endpoint, like this:
In the Swagger demo, however, operations are hidden by default until the user chooses to show them.
Is there a configuration option for ApiDoc that will hide operations by default? I haven't found anything like this in the documentation.
Documentation section can be hidden by default with parameter default_sections_opened:
nelmio_api_doc.default_sections_opened: false
Default value for this parameter is true. See configuration reference.
You must change your config.yml file like this (default_sections_opened to false):
nelmio_api_doc:
name: 'API documentation'
exclude_sections: []
**default_sections_opened: false**
motd:
template: 'NelmioApiDocBundle::Components/motd.html.twig'
request_listener:
enabled: true
parameter: _doc
sandbox:
enabled: false

knp_paginator failed to open stream

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.

"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: [] .......

Resources