Questions tagged [symfony2]
Symfony2 is an open source PHP web development framework for PHP 5.3.9+ focusing on easy and fast development cycles and including state-of-the-art design patterns and programming philosophies. Symfony should not be confused with Symphony CMS
30 questions
1
vote
0
answers
715
views
Symfony controller to register and activate users
I've been in an interview some time ago. They objected my Symfony API code with following line:
Too much code in controller actions. Can be moved to services to keep
the business logic apart from ...
2
votes
1
answer
151
views
Model database for contract renewal
I have made a contract renewal system in Symfony and Doctrine, and it works, but I think it can be improved, but I make too many requests to the database.
These are my models:
...
5
votes
1
answer
100
views
Migrate data between tables efficiently
I wrote a very simple quick and easy script to migrate a bunch of data to another table in my database.
Can I accomplish this task without using so many foreach loops?
I realize I'm imputting ...
2
votes
1
answer
541
views
MVC controller and action that handles favorite items in a session-based list
I've written a Controller and a corresponding Action for a Symfony 2.8 project, that does the following:
handles a list of favorite items of a user
the ids of the favorites are stored in the session
...
3
votes
1
answer
246
views
Redirecting the web client after deleting an item
In my web-app, it is possible to delete an Item when visiting any of 4 different pages:
the Show Item page
the Edit Item page
the List Items page
the List Items in Room page
If the visitor uses a ...
2
votes
1
answer
982
views
Doctrine/Symfony WHERE clause for reports
I'm trying to generate a report from two doctrine entities.
The fields to filter the report are optional. This is the code I've got now and it looks really bad to me. How can I improve this?
...
0
votes
1
answer
106
views
Updating data on a blog
I want to make post editing on my blog. I get data from a form and want to put it into a database. I'm not sure if using setters is the best way, so maybe you can show me better solution?
...
1
vote
1
answer
2k
views
Preventing XSS in a Symfony form to add a timetable entry
I have started to implement cross site scripting prevention (xss) within my code.
However as I am using symfony for this particular project I have read up that nothing needs to be done for xss in ...
4
votes
1
answer
1k
views
PHP routing system
I made a routing system for PHP inspired by Symfony's router composed of a few classes.
First I am using Symfony's HTTP Foundations component.
Then, I am emulating the classes in the routing component ...
2
votes
2
answers
825
views
Validating user credentials and logging into a Symfony site
I have the following code in a Symfony site that validates a user's credentials and logs them in via the Session class:
...
4
votes
1
answer
216
views
Using a separate class in Symfony to handle a list of entities with controller injection
In my Symfony (v2.7.9) project I have a set of entities which share some view functionality i.e being displayed in a table with some of their values as columns.
Following the separation of concerns ...
5
votes
3
answers
250
views
Get similar posts with manyToMany relationship
I have a table post with a many-to-many relationship with the tag and product tables.
...
2
votes
1
answer
828
views
Silex - Guzzle call to external API
I'm at the point where I am happy with the functionality of my code but I dislike how its written. It seems like I can be more modular with it but I can't seem to figure out how to improve on it ...
4
votes
1
answer
86
views
Inserting and updating data for a website monitoring app
I have created an app in which URLs stored in a database are pinged via curl to check their availability and the database is updated with the results.
Two tables are updated with each fresh ping of a ...
2
votes
1
answer
121
views
Logging and getting the response in a controller
I have an action that does two things:
It sends a chain of commands, and gets the response from an external API that we call wrapper.
It logs the chain of commands ...
0
votes
2
answers
3k
views
Shuffle Symfony entities
I've got an object $contest which is a Symfony entity that has some other entities assigned. I can get them by ...
3
votes
1
answer
104
views
Tag manipulation using DOMDocument
On our main symfony2 application at work I have had to manipulate some outputted grid fields by wrapping them in a hyperlink tag. This happens in quite a few different controllers, so I made a method ...
2
votes
0
answers
105
views
View helper for creating HTML elements with DOM
I have attempted to create a view helper class which makes programmatically creating HTML strings less verbose and hopefully simpler.
This is inspired by the tag helpers in Rails. It's compatible ...
2
votes
0
answers
119
views
Which pattern could help to refactor this controller code?
I know I should use services and patterns to refactor this controller action, but I can't imagine one that could fit/be appropriate for this problem.
It seems a strategy or template, but a strategy ...
62
votes
3
answers
52k
views
Trait accessing variables of classes using it
I just tried PHP Traits for the first time, to keep my code DRY :
...
11
votes
2
answers
14k
views
Fetching objects and adding a calculated field in Doctrine 2
I'm making a section that shows a list of blogs and how many comments it has without loading any comment data. My Blog entity is as follows:
...
1
vote
1
answer
2k
views
Checking if a relationship exists
I'm using a many-to-many relationship between users and roles with propel:
...
2
votes
1
answer
4k
views
Uploading a file using Symfony 2.5 strictly
Recently I have been looking into Symfony framework and I am working on a task where I need to upload a file using a form. Once the form has been submitted I need to insert the user input along with ...
3
votes
0
answers
659
views
Building a console application using a DI service container
I am working on a project that will allow developers to create a console application using a dependency injection service container. Both the console and container are Symfony components with some ...
6
votes
1
answer
149
views
Uploading file for related entity
I see that my code smells. The first file is a controller, and createAction. But I don't know where to delegate this.
BookController.php - Whole controller class
So this is most 'smelly' code to ...
3
votes
1
answer
4k
views
Linking to an image asset from a JavaScript file in Symfony 2
I am calling a JS file from a bundle directory like so:
<script src="{{ asset('bundles/macppages/js/main.js') }}"></script>
which loads the JS file ...
2
votes
1
answer
162
views
Handling library entity
Below you'll find a Symfony2 service I wrote to assist in handling the Library entity. Each user in my app has a personal library where one can upload items to and a purchased library, that contains ...
1
vote
1
answer
226
views
Database "design" using Symfony2 and Doctrine2
I'm working on an application, which tracks expenses. I have users, and each user can create his categories for the expenses (like Food, Bills, Transport, Drinks, Clothes) and then create expenses - ...
3
votes
1
answer
1k
views
Friends edit form
I have a list of friends and new friends are added via a form. When you click on a friend you see all the information about him. There is also an Edit button. When clicking it, I want a form to be ...
3
votes
1
answer
3k
views
Unit-testing ExtFilterParser Symfony2 service
The Service:
...