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

Filter by
Sorted by
Tagged with
1
vote
0answers
70 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 ...
2
votes
1answer
94 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
1answer
65 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
1answer
205 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
1answer
166 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
1answer
603 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
1answer
67 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
1answer
947 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 ...
1
vote
0answers
253 views

Inheritance and Association implentation in Symfony 2.7 and Doctrine

I've a working implementation in Symfony2 with doctrine of the following model. A Parent can apply for one/more Training(s) A Training is based on a specific Skill, but you can have multiple ...
3
votes
0answers
925 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 ...
2
votes
2answers
639 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
1answer
181 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
3answers
179 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
1answer
777 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
1answer
44 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
1answer
86 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
2answers
2k 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 ...
1
vote
0answers
286 views

FilesSynchronizer: Synchronize local and remote filesystems

I have written a library that syncs files between two filesystems. It works fine, but I'd like some other developers to have a look over the existing code. Maybe I can optimize something. It is using ...
3
votes
1answer
85 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
0answers
83 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
0answers
96 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 ...
54
votes
3answers
37k views

Trait accessing variables of classes using it

I just tried PHP Traits for the first time, to keep my code DRY : ...
8
votes
2answers
10k 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
1answer
774 views

Checking if a relationship exists

I'm using a many-to-many relationship between users and roles with propel: ...
2
votes
1answer
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
0answers
605 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
1answer
118 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 ...
1
vote
0answers
193 views

Form-processing controller action

I have a fairly ugly controller method I would like to refactor / extract. I can only test this in an integration-type test which kind of signals a code smell. The method processes the form and needs ...
3
votes
1answer
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
1answer
125 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
1answer
209 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
1answer
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
1answer
3k views

Unit-testing ExtFilterParser Symfony2 service

The Service: ...