FAQ Database Discussion Community


“Unable to open database file” error when trying to load Doctrine Data Fixtures in Symfony

symfony2,doctrine2,behat
I'm using pdo_mysql for prod, stag and dev environments and pdo_sqlite for test environment. The problem is that loading Doctrine Data Fixtures generates unable to open database file error as shown below. I assigned the permissions to cache folder as defined in symfony website and also tried with 777 but...

Symfony2: changing the request class and updating the test environment

php,symfony2,request,phpunit
I have modified the base Request class of my application as explained in the accepted answer of this question. It works very well, except when launching my functional tests, I get the following error: Controller "My\Bundle\AppBundle\Controller\MyController::searchAction()" requires that you provide a value for the "$request" argument (because there is no...

Conflicts in routing in symfony between bundles

symfony2
Playing around with symfony. I have two bundles and each bundle has a controller within it. Just to see how routing works I gave the same path to functions within both controllers. Bundle B was the newly created bundle and when the URL app/simple was hit I got a response...

Set Auth Token manually for different firewall

symfony2
My application has 2 security firewalls "admin" - used by internal staff "account" - used by customers. Previoly I had one action under the account firewall, the action in the controller looks something like this. $user = //get user somehow $token = new UsernamePasswordToken($user, null, 'account', $user->getRoles()); $this->get('security.token_storage')->setToken($token); With this...

Symfony2 Doctrine: ContextErrorException: Catchable Fatal Error: Object of class DateTime could not be converted to string

php,symfony2,doctrine2
In my Symfony2 project I have the following query in my ProductRepository.php: $dateNow = new \DateTime(); $query = $this->createQueryBuilder('p') ->update('MyBundle\Products', 'p') ->set('p.published', $dateNow) ->getQuery(); $query->execute(); ProductEntity.php: /** * Set published * * @param \DateTime $published * @return Product */ public function setPublished($published) { $this->published = $published; return $this; } ERROR:...

ClassNotFoundException Symfony UserBundle

symfony2,fosuserbundle
I'm developping a website on Symfony2, I want to intergrate FOSUserBundle. I am using Doctrine ORM User class. I've followed the installation steps but I got this error: ClassNotFoundException in AppKernel.php line 21: Attempted to load class "FOSUserBundle" from namespace "FOS\UserBundle". Did you forget a "use" statement for another namespace?...

Symfony Functional Testing: how to understand why the test fails (with a 500 Error)

php,symfony2,phpunit,functional-testing
I'm writing functional tests for a controller that registers a new user in the app. The test I'm writing fails because of a 500 HTTP error. I'm using $response = $client->getResponse(); print_r($response->getContent());exit; to print the HTML to see what is happening but the HTML is incomplete in my console (PHPStorm)...

how symfony2 remember me work without any table for token?

php,symfony2,cookies,remember-me
I configure symfony2 to add remember me functionality, but how it work without any table in database to save remember me token. I mean some best practice for remember me cookie like what is said in here

Use a PHP file to Symfony

php,symfony2,elasticsearch
I have a PHP file which is connected to elasticsearch, where I am indexing my documents. My elasticIndex.php file: **class elasticIndex{ function elasticFun(){ require 'vendor/autoload.php'; $client = new Elasticsearch\Client(); $feed = 'http://blaasd.zasdp.tv/Xml'; $xml = simplexml_load_file($feed); foreach ($xml-> ....... ......}** Now the problem is I am working on Symfony framework, where...

Add brands through company, it's possible? How?

php,symfony2,doctrine2,mapping,symfony-2.6
I have this two tables (see pics below) mapped as follow: class Brand { ... /** * @var Company * * @ORM\ManyToOne(targetEntity="Company") * @ORM\JoinColumn(name="companies_id", referencedColumnName="id") */ protected $company; } class Company { ... } I need to add support for add a new Brand from Company but I have not...

Symfony 2 : Generated bundle will not find routes

php,symfony2
I understand that symfony recommends to use the default AppBundle (as stated in this page http://symfony.com/doc/current/best_practices/creating-the-project.html), however because my project is comprised of a number of stand-alone apps, I would like to separate them into their own bundles. I am trying to generate a bundle with help of the symfony2...

Symfony Doctrine findBy and then map

php,symfony2,doctrine2,doctrine
Basically I want to execute this mysql query with doctrine: select distinct user_id from work_hour where project_id = ?; But I don't know how I can do this with pretty Doctrine code. Is it possible to make it look like the following pseudo code or do I have to use...

Symfony2 move app.php from web directory to root directory

symfony2
I moved app.php from web directory to root and i change the following two lines: $loader = require_once __DIR__.'/app/bootstrap.php.cache'; require_once __DIR__.'/app/AppKernel.php'; Also i move .htaccess file from web directory to root , my problem is that now the system cannot find JavaScript and CSS files....

Symfony2 - assets do not load

javascript,php,css,symfony2,assets
Today again something doesn't work in my symfony2 test project. Now i'm trying to use some assets like .css file and images. What did i do so far? Bundle name is MyValleyBundle so in AppKernel.php bundle is registered: new My\ValleyBundle\MyValleyBundle(), I did put files respectively css to css, images to...

Doctrine OneByOne's and Date

php,symfony2,doctrine2,entity
I am using Symfony 2.7.1 and I seem to have a problem while using my News Entity. I am trying to use the published_at in my twig template. I tried using {{ news_item.published_at|date("m/d/Y") }} but that seems to follow up by a fatal error: Method "published_at" for object "AppBundle\Entity\News" does...

Doctrine persist entity with inverse relation not work

symfony2,doctrine2,entity
I'm trying to save two entities linked. Product entity may have any or many entities ProviderRate. When I try to save the product entity, it tells me that ProviderRate related entity has not assigned one of their required fields. I need to save a product with no need to assign...

Symfony / Sonata Admin: List form on Edit form

php,symfony2,sonata-admin,symfony-sonata,sonata
I have a one (category) to many (product) relationship set up, and I'd like to have a list of products show up at the bottom of the edit category page. It seems like this would be a common thing to do, but I haven't found any way to do it...

Starts with Symfony2 : No route found for “GET /”

php,symfony2,install
I just installed Symfony2 on my Mac. My web/config.php works fine but when I go to the web/app_dev.php file, it shows me an error : No route found for "GET /" (from "http://localhost:8888/Symfony/web/config.php") 404 Not Found - NotFoundHttpException 1 linked Exception: ResourceNotFoundException ERROR - Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route...

How to concatenate a parameter value with a constant string in Yaml

symfony2,yaml
I'm using Symfony2. I have an url defined as a parameter in parameters.yml. I want to create a service which is a SOAP client. The argument of the SOAP client is an url for a wsdl file. In my case, the url of the wsdl file is "%parameter_url%" + "?wsdl"....

Symfony class no field or association

php,symfony2
I've added a new column in my database for my contact table called added_date added this column to my contact entity class Acme\Entity\Contact $added_date added get-setters called getAddedDate() and setAddedDate() class Contact { private $added_date; public function __construct() { $this->added_date = new \DateTime(); } public function getAddedDate() { return...

Nested menu items at SonataAdminBundle sidebar

php,symfony2,sonata-admin,symfony-sonata,sonata
I would like to nested menu items like a tree. I have this configuration at the moment: dashboard: groups: company: icon: <i class="fa fa-lg fa-fw fa fa-cogs"></i> label: Company items: - sonata.admin.company - sonata.admin.brand - sonata.admin.media - sonata.admin.message territory: icon: <i class="fa fa-lg fa-fw fa fa-cogs"></i> label: Territory items: -...

Using Twig Variables inside config.yml

symfony2,twig
Is it possible to use variable values for defining new twig globals in a configuartion-yml-file? The situation is, that we want to define the domain name at the one hand and at the other define often used paths (but using the already defined variable instead of writing the server name...

Include a method when object is serialized in JMS

symfony2,serialization,jmsserializerbundle
I have a method that returns a value: /** * @ORM\Table() * @ORM\Entity(repositoryClass="PersonRepository") */ class Person { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; public function getFoo(){ return $this->id + 1; } //setters & getters } I would like to include the...

Symfony change validation message globally

php,symfony2,symfony-2.3
Is there a way to change the basic validation error message to one I need for all entities at once? Currently using Yaml config for every entity, but it's not a way. CF\MyBundle\Entity\User: properties: email: - Email: message: e-mail no válido - NotBlank: message: Campo obligatorio username: -NotBlank: message: Campo...

Symfony2 Catchable Fatal Error: Argument 1 passed to entity Catchable Fatal Error: Argument 1 passed to entity

php,forms,symfony2,entity,symfony-2.6
I got this error and I'm stuck since many hours Catchable Fatal Error: Argument 1 passed to Thinking\ThinkBundle\Entity\InYourMind::setThinkFriend() must be an instance of Thinking\ThinkBundle\Entity\InYourMindFriend, array given, called in /var/www/html/thinkroulette/vars/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 410 and defined I searched for this issue and lots of results came up but I wasn't capable to...

How to create a console command in Symfony2 application

php,symfony2,symfony-2.6,symfony-components,symfony-console
I need to create a console command for a Symfony2 application and I read docs here and here though I am not sure what of those I should follow. So this is what I did. Create a file under /src/PDI/PDOneBundle/Console/PDOneSyncCommand.php Write this code: namespace PDI\PDOneBundle\Console\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use...

Symfony Crawler: how to check that a link to a particular page exists

php,symfony2,phpunit,functional-testing
I'm writing some functional tests and i want to verify that the Edit link exists on the page if the user is logged in. The link is a simple <a href="/profile/22/edit">Edit</a>. How can I filter it using the Crawler component of Symfony? One solution is this: $this->assertEquals(1, $crawler->filter('html:contains("<a href="/profile/22/edit">")')->count()); But...

Update session in symfony2 for shoppingg cart

php,symfony2,symfony-2.1,php-5.3,symfony-2.3
I have the following code : public function addAction(Request $request){ //Get submited data // Get Value from session $sessionVal = $this->get('session')->get('aBasket'); // Append value to retrieved array. $aBasket = $request->request->all(); if(count($sessionVal) > 0) { foreach ($sessionVal as $key=>$value) { if($aBasket['product_id'] == $sessionVal[$key]['product_id']) { $sessionVal[$key]['product_quantity'] = $sessionVal[$key]['product_quantity'] + $aBasket['product_quantity'];...

OAuth HwioBundle, different socialNetWork

php,symfony2,oauth,hwioauthbundle
I work to projekt in Symfony wich have regisrtation HWIOBundle for different social network. If user enter for example linkedin and some time for github I has two user in database. Who knows how to do was one?

Transfert a Zend Project to Symfony

php,symfony2,zend-framework
I have a project made using Zend. My boss asked me to change the technology to Symfony 2.7. Is there a way to transfer the project ? Or to take some files into Symfony ? Or should I begin all the project from scratch using Symfony ? Thanks !...

Symfony2 fail during installation

php,symfony2
I am trying to use Symfony2 with a local wamp server. I used php -r "readfile('http://symfony.com/installer');" > symfony I moved the symfony file to C:\wamp\www\test. And php symfony php symfony new myProject But this message appear Warning: include(phar://C:/wamp/www/Symfony/symfony/vendor/symfony/process/Symfo ny/Component/Process/ProcessUtils.php): failed to open stream: phar error: Canno t open phar archive...

avoiding container strings in dependency injection in symfony

php,symfony2,dependency-injection
New to symfony and php. I was able to successfully define a service and inject the doctrine entity manager into it. It works fine but during the initialization I have to pass a string that contains the service name as follows: $eRep = $this->container->get('employee_repository'); Can this be avoided? Can this...

Change role of one user no working with Symfony2

symfony2,fosuserbundle,roles
Sorry if this question has been asked many times but I didn't found any solution on the Web. So, I just have installed FOSUserBundle and I've created 2 users on my application with the console. The problem is they don't have any role. So in on controller, I get the...

Unique Entity Error message

api,symfony2,exception-handling,doctrine
I have a user entity which have some unique fields. The code bellow shows you how I defined it. /** * @UniqueEntity(fields={"login"}, message="UNIQUE ERROR MESSAGE") */ ...... /** * @var string * * @ORM\Column(name="login", type="string", length=255, unique=true) */ private $login; Developping an API, I would like to be able to...

Remove automaticaly entity in BD when choice value not selected (or null selected)

php,forms,symfony2,doctrine
I would like to know if symfony/doctrine can manage automaticaly the fact that instead of setting the value of my entity to null it could symply remove it. (by removing it I mean the records where the value equal null) exemple: I have a PICTURE entity linked to a VOTE...

Logs an entire array using Monolog [closed]

php,symfony2,monolog,symfony-2.6
Is there any way to log an entire array using Monolog? I have been reading several docs but didn't find a way to log the entire array in a readable format, any advice? Docs I've read: Monolog, how to log PHP array into console? http://symfony.com/doc/current/cookbook/logging/monolog.html https://www.webfactory.de/blog/logging-with-monolog-in-symfony2 ...

Symfony2 & PHPUnit - Access getContainer()

php,symfony2,login,parameters,phpunit
I have a problem with my PHPUnit test on symfony2. To connect to my application, I use a web service, so I created a UserProvider. In my function loadUserByUsername I use symfony2 parameters saved in app/config/parameters.yml. As I'm not in a controller I need to use the global variable $kernel...

display the name but insert the id whit entity field type

symfony2
the form is the entity services namespace Main\HomeBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class ServicesType extends AbstractType { /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('techId', 'entity', array( 'class' => 'MainHomeBundle:Technical', 'property' => 'id', )) ->add('status', 'choice',...

Form get data from collection

symfony2
I have a FormType "Questionnaire" and a Subform "Question" as collection. The subform "Question" have a form value which is not mapped by the entity "Question". How can i access the not mapped value from the subform / collection in the controller which receives the main form "Questionnaire" for saving...

I can't do update with an entity in my select symfony 2

symfony2
$builder ->add('tecnicoId', 'entity', array( 'class' => 'MainHomeBundle:Tecnicos', 'property' => 'nombre', 'expanded' => false, 'multiple' => false )) ->add('cambiar', 'submit') ; controller $form = $this->createForm(new ServicioseditType(), $datos); $form->handleRequest($request); $em = $this->getDoctrine()->getManager(); $em->flush(); return $this->render('MainHomeBundle:Admin:editserv.html.twig', array("form"=>$form->createView())); view twig {{ form_errors(form.tecnicoId) }} {{...

Securing Symfony RESTful API consumed by angular front?

angularjs,api,symfony2,oauth,wsse
I have set up a Symfony based API which is being used by an Angular front end which is totally dependent of it (User registration included) I have read multiple threads recommending using WSSE or FOSOAuthServerBundle but I'm not sure about the best method ? If I understood correctly, WSSE...

Symfony2: ajax call redirection if session timedout

ajax,symfony2,session
I have a working dashboard with ajax request. I fire an ajax request on some events which will update a part of the dashboard. But if the session has expired, the part will be refreshed with the login page. How can i do a redirection after the ajax call if...

AppBundle's Best Practice and how-to go further

php,symfony2,doctrine2,entity
According to this page on the documentation website of symfony they explain how to address your application logic and the best practices. The one thing I am missing in this documentation is the way to store and use your entities. There is a small section that covers the usage of...

Dependencies in forms Symfony2

php,forms,symfony2,events,entities
I'm working on a webapplication in Symfony2. I came to a point in which I need some advice/explanation from some one more advanced in Symfony. I have a part of my database that is set up as follows: I have cards that belong to a card attribute set and consists...

Symfony “No route found for ”GET /check.php" fresh install

php,symfony2,http-status-code-404,symfony-2.7
I've just installed Symfony 2.7. I've started my app from the command line with: $ php app/console server:run I installed XAMPP to run PHP. The following pictures show my localhost:8000/config.php and localhost:8000 pages. Config ! Main page ! EXACT SOLUTION: _blog: path: / defaults: { _controller: AppBundle:Default:index } Where: path...

Store entity from session doesn't work => $em->persist()

php,symfony2,doctrine2
at first: Sorry for my poor english :-) A beginner need help! I have 3 entities/tables: Tables: contact_person id, title, firstname, surname, adress_id address id, street, zip, city, country_id country (fix values) id, name, code 1, Austria, AT 2, Germany, DE ... Entities: /** * ContactPerson * * @ORM\Table(name="contact_person") *...

Append inline scripts inside Twig layout block

php,symfony2,templates,twig,fosuserbundle
I have a layout that looks like this: <html> <body> <!-- Omitted --> <div class="content"> {% block body %}{% endblock %} </div> <script src="js/vendor.js"></script> {% block javascripts %} <!-- I want to be able to inject inline scripts from sub-templates here --> {% endblock %} </body> </html> Then I have...

Force Uppercase on Symfony2 form text field

php,forms,symfony2
I've inherited a Symfony2 project that has a form built as such: $builder ->add('Status', 'choice', array( 'choices' => array('' => '', 'PASS' => 'PASS', 'FAIL' => 'FAIL', 'INCOMPLETE' => 'INCOMPLETE', 'DROPPED' => 'DROPPED',), 'required' => FALSE, )) ->add('First_Name', 'text', array('label'=>'First Name', 'required' => FALSE)) ->add('Last_Name', 'text', array('label'=>'Last Name', 'required' =>...

Attempted to load class “COM” from namespace -Symfony2

php,class,symfony2,ms-access
I am developing a web using symfony2 framework. In this web the users upload file(.mdb). The web read the file and if the information is correct it pass to database.(This is the idea) The problem is that i try to used "COM class of PHP". First i think that i...

order attribute of an object in Synfony

php,symfony2
I would like to reorder the attribute (COMMENTS) of my object (instance of ARTICLE) after I retrieve it from the DBB. Is this possible? My object is ARTICLE and it is linked to COMMENTS (which is defined as a collection in entity article) I know I can order through the...

Symfony2 creating and persisting entity relationships

php,mysql,symfony2,doctrine2
I have two entities Skin and Email. I want Email to be a part of the Skin entity, however I can't use the console to update schema automatically right now, and that is probably why I can't get the relationship to work. So I want to store all the Emails...

Symfony 2: “No route found for ”GET /" - error on fresh installation

php,symfony2
I'm trying to begin my education of symfony 2 and started with its tutorial. One of first things i tried is to install symfony 2 and configure it. When i'm trying to access http://127.0.0.1:8000/ i'm getting incomplete site with error: ERROR - Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for...

Adding own action to SonataAdminBundle dropdown menu

symfony2,sonata
We use the SonataAdminBundle with our Symfony2 application. When editing an entity I want to add an own action to the dropdown menu which is located in the top right corner, but I have no idea how this works. I know I can add own routes via configureRoutes(RouteCollection $collection) and...

symfony twig render dynamic twig code

symfony2,twig
In my symfony2 action, i have: $twigCode = '<li>{{ data.value }}</li>'; //In database $datas = array(array( 'value' => 'line 1'), array( 'value' => 'line 2')); return $this->render( '...List.html.twig', array( 'twigCode' => $twigCode, 'datas' => $datas ) ); In my twig template, i want something like: <ul> {% for data in...

WebTestCase, Silex and $_GET

symfony2,silex,web-testing
I'm experiencing some issues on a WebTestCase using Silex: on one of my controller's action, I need a parameter passed through a normal $_GET (I have to as it's an URL, and Apaches interprets the %2F if it's outside of the query string -- see Url Variables with %2f not...

Using crontab to call wget every 5 minutes

php,symfony2,crontab,wget
I am working on a project where the wget and crontab are used to run a process in the background. I have a php file named "Hello.php" that I want to run this every 5 minutes. I have found that if I want to have a cron job run every...

Symfony2 service unable to find template

php,email,symfony2,templates,twig
I've just pulled an all-nighter trying to get this to work, and I'm probably missing something foolish, but help me out. I have a symfony2 service which sends emails. I have injected the @templating service into my service's constructor like so: services.yml order_service: class: AppBundle\Services\OrderService arguments: [ "@doctrine.orm.entity_manager", "@mailer", "@templating"...

Symfony 2 unable to pass entity repository to form

php,forms,symfony2,runtime-error
I have a form with a drop down and a set of checkboxes, i've used entity form field type to get the values via DB. it works with one of the entity but not with the other. i have this code seperately inside AddBadgesType there is NO AddBadges entity <?php...

Setting cookie for AngularJS translate locale using PHP

php,angularjs,symfony2,angular-translate
My app uses Symfony and AngularJS. I have translations some with Symfony itself and some with AngularJS angular-translate. How do I set a cookie or session variable to change language for AngularJS from PHP?

Class inheritance in Symfony2

php,symfony2,doctrine2
I'm a bit confused about an error that I'm getting: Undefined method 'getAsArray'. The method name must start with either findBy or findOneBy! getAsArray() is a method in my repository class, it's called in PostsController.php like so: $categoriesList = $this->getDoctrine()->getRepository('AirBlogBundle:Category')->getAsArray(); CategoryRepository.php is defined like this: namespace Air\BlogBundle\Repository; class CategoryRepository extends...

Symfony/Twig radio style formbuilder

php,symfony2,twig,formbuilder
I need to style each of radio button using Symfony form builder. This is my part of my createFormBuilder: ->add('categoryId', 'entity', array( 'class' => 'MyBundle:Category', 'property' => 'name', 'required' => false, 'expanded' => true )) And in my twig template: {% for child in form.categoryId %} <div class="radio i-checks col-md-3">...

Symfony/Twig how to render a Route set by anotation?

php,symfony2,routing,twig,url-routing
Let's say I have this code in a controller: <?php namespace Foo\BarBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration as Mvc; /** * @Mvc\Route("/foo/bar") */ class TestController extends Controller /** * @Mvc\Route("/test/{id}", requirements={"id" = "[0-9]{1,6}"}) * @Mvc\Template * * @return view */ public function testAction($id) { return array('test' => $id); } } How...

Silex - How to process template includes separately

symfony2,templates,include,silex
I've got a Twig base template like so: {% include "./partials/navigation.html" %} <!-- Main Wrapper --> <div id="wrapper"> {% block content %}{% endblock content %} </div> I also have a route controller which is outputting the response content to the page using twig: return template->render('path/to/teplate', args()); where args[] array is...

Get dates in “human readable” format

php,symfony2,date,fosrestbundle
I am working in a RESTFul API using Symfony2 and FOSRestBundle. The entities use Gedmo for Timestampable options: use Gedmo\Timestampable\Traits\TimestampableEntity; And I get the createdAt as any other column: $obj->getCreatedAt() Then I pass that response to FOSRestBundle: $respEmail = [ "id" => (string)$entEmail->getId(), ... "category" => $entEmail->getEmailsCategory(), "createdAt" => $entEmail->getCreatedAt()...

Semantical Error in symfony2 while fetching the data

symfony2
I am trying to write a web service to fetch the category list and all the business under that category in an nested array fashion. I am getting an Semantical Error saying : { code: 500 message: "[Semantical Error] line 0, col 14 near 'StreetBumbApiBundle:Buss_owner': Error: Class 'StreetBumb\ApiBundle\Entity\Buss_owner' is not...

Deserializing or parse XML response in Symfony2

php,xml,symfony2,deserialization,jmsserializerbundle
I am calling a API method through cURL and I got this response: <?xml version="1.0" encoding="UTF-8"?> <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"> <id>75080000002s5siAAA</id> <operation>query</operation> <object>User</object> <createdById>00580000008ReolAAC</createdById> <createdDate>2015-06-23T13:03:01.000Z</createdDate> <systemModstamp>2015-06-23T13:03:01.000Z</systemModstamp> <state>Open</state>...

How to write and use Monolog handlers and channels

php,symfony2,monolog,symfony-2.6
I have read some docs here but still not clear to me how to write and use a custom Monolog handler and channel. Let me explain a bit what I want to achieve. I have a custom function and I want that log to be logged into a file called...

entities relations with doctrine (symfony 2)

symfony2
I start a project with symfony. I debute with the design of the data base. My project consist to manage the treatment cycle of the an patient with several entites. concretely: An entity patient should have a relation with social security entity, hospital, pharmacy, doctor , nurse, Personne to contact,...

With a OneToMany relation between entities, how create the right queryBuilder with Doctrine (on the Inversed Side entity)

php,symfony2,doctrine2,one-to-many,query-builder
I have these 3 entities in my symfony2.6 project: Compteurs.php class Compteurs { /** * @var \PointsComptage * * @ORM\ManyToOne(targetEntity="PointsComptage", inversedBy="compteurs") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="pointscomptage_id", referencedColumnName="id") * }) */ private $pointsComptage; /** * @var \Doctrine\Common\Collections\Collection * * @ORM\OneToMany(targetEntity="ParametresMesure", mappedBy="compteurs") */ private $parametresMesure; ParametresMesure.php: class ParametresMesure { /** * @var Compteurs...

Symfony Array Collection as Entity Property

php,symfony2,doctrine2
Is there a way to associate an ArrayCollection to a database column created by an Entity? For example, I have two entities: Household and Pet Type. Household current has a property for Pet Type, but it expects the Pet Type object, so only one can chosen at the moment. I'd...

comparison operator is not working in twig

php,symfony2
problem in comparing dates in twig. case if event is ongoing or is about to begin within 7 days. twig code {% set event_startdate=data.detailes.data.event.event_startdate|date("d-m-Y")%} {% set event_enddate=data.detailes.data.event.event_enddate|date("d-m-Y") %} {% set upcoming_days =daysdiff(event_startdate)|date('d-m-y') %} {% set stdate= "now"|date('d-m-y') %} {% if event_startdate >stdate and event_startdate < upcoming_days %} // condition...

Symfony2 relationship between two entities

php,mysql,entity-framework,symfony2
I want to make a relationship between two entities but for some reason I am getting NULL on one of the values... So in my skin entity I have an email_registration_id field with the relationship : /** * @ORM\ManyToOne(targetEntity="Project\UserBundle\Entity\Email") * @ORM\JoinColumn(name="email_registration_id", referencedColumnName="id") */ protected $email_registration_id; /** * Set email_registration_id *...

How adapt the path to the previous and next article

php,symfony2
I am looking for a solution to access in the current article to the previous(<<) or the next article(>>) at the end of the page of an article. I thought to get the current paramater of the url with this : {{ dump(app.request.attributes.get('_route_params')) }} and inject in the path with...

Symfony 2 - Class “Mingle\StandardBundle\Entity\Product” is not a valid entity or mapped superclass

php,symfony2,doctrine,entity,bundle
I created a Product.php file in my bundle Mingle\StandardBundle\Entity like this: <?php namespace Mingle\StandardBundle\Entity; use Doctrine\ORM\Mapping as ORM; /* * @ORM\Entity * @ORM\Table(name="product") */ class Product { /* * @ORM\Column(type="integer") * @ORM\ID * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /* * @ORM\Column(type="string",length=100) */ protected $name; /* * @ORM\Column(type="decimal",scale=2) */ protected $price; /*...

Dropzone.js and symfony formbuilder

javascript,php,symfony2,formbuilder
I'm trying to handle dropzone.js to work correct with my entity symfony formbuilder. Everything works properly if I'm using simple <input type="file" id="form_file" name="form[file]"> BUT if I'm using dropzone.js I get this difference in my POST: How I can handle it? This is my js for it: Dropzone.options.myAwesomeDropzone = {...

Symfony2 form builder without class check if multiple fields are empty

validation,symfony2,constraints,formbuilder
I am using form builder without class and have two fields with each having constraints : $form = $this->createFormBuilder() ->add('name', 'text', array( 'required'=>false, 'constraints'=> new Length(array('min'=>3) )) ->add('dob', 'date', array( 'required'=>false, 'constraints'=> new Date() )) ->getForm() ->handleRequest($request); This works great but I want to check if both fields are emtpy,...

Symfony FOS editing/updating username/email

php,symfony2
Hello I'm trying to make user update/editing system with symfony FOSUserBundle and I have little problem currently I'm able to load existing username and email with following code: public function editAction(Request $request, $id) { $userManager = $this->get('fos_user.user_manager'); $user = $userManager->findUserBy(array('id' => $id)); $form = $this-> createFormBuilder($user) ->add('username') ->add('email') ->add('save', 'submit')...

How can i view Result of Database from doctrine in twig

php,symfony2,doctrine2,twig
Edit: change findOneBy to findBy In symfony I am using the FOS-UserBundle. I have three tables. fos_user customer customer_user This is the customerUser.orm.xml <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity...

How to query in Doctrine2 WHERE = 'value from a related Entity'

php,json,symfony2,orm,doctrine2
The relationship is as easy as Many posts -> one User // Acme\AppBundle\Entity\UploadPlugin\Post /** * @ORM\ManyToOne(targetEntity="Acme\AppBundle\Entity\AuthBundle\LiveUser") * @ORM\JoinColumn(name="posts", referencedColumnName="id") **/ private $postOwner; So when I create a new Post like this : $image = new Post(); $image->setName($imagetitle); $image->setPostowner($this->getUser()); //(...) set further stuff $em = $this->getDoctrine()->getManager(); $em->persist($image); $em->flush(); I'd just return...

Symfony2 get logged in user instance from custom User class

symfony2
I have my own custom User class implementing the UserInterface. A snippet follows: class User implements UserInterface { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="username", type="string", length=30, unique=true) */ protected $username; ... /** * Get...

Redirecting all ip to maintenance page except some ips

apache,.htaccess,symfony2
When releasing new versions of my Symfony project, I need to redirect all external ip addresses to a maintenance.html page (which lives into symfony web directory) using apache. Here is the virtualhost file configuration I've created for this purpose but: When I go from an external ip I get 403...

Embedded form entity is not persisted

symfony2
Symfony 2.6.9 I have UserProfile entity with avatar property which has oneToOne uni-directional relation to UserAvatar entity and cascade persistence. BlogBundle\Entity\UserProfile: type: entity table: user_profiles id: id: type: integer generator: strategy: AUTO fields: #... oneToOne: #... avatar: targetEntity: UserAvatar cascade: ['persist', 'remove'] And I created UserProfile form type with embedded...

Symfony\Component\Config\Exception\FileLoaderLoadException] error

php,symfony2,twig,swiftmailer
Hi I stumble upon this error everytime I want to run my Symfony application from console. Therefore I am unable to use this symphony app at all. Please help me with your knowledge. [Symfony\Component\Config\Exception\FileLoaderLoadException] Unable to parse at line 9 (near "mailer_transport="gmail"") in /opt/lampp/htdocs/symblog.dev/app/config/parameters.yml (which is being imported from "/opt/lampp/htdocs/symblog.dev/app/config/config.yml")....

Symfony files which are included in CSS are not found when using assetic

css,symfony2,twig,assetic
I'm using Symfony with Twig and I use assetic. The problem is that my CSS file includes other CSS files like that: @import url(ie8.css); @import url(blocks.css); @import url(plugins.css); @import url(app.css); And these files are not found when webpage is displayed. Same happens with fonts and images. How do I solve...

Symfony2/Twig - iterate over select options

php,symfony2,twig
Usual way of displaying select field is to call {{ form_row(form.doctor_service_id, {'attr':{'class':'form-control'}}) }} I would like to perform two things: Check if this field is actually a select field Iterate over every option (value, name). I know how twig iterator works, I just don't know how to access select options...

wkhtmltopdf on openSuSE: cannot connect to X server

php,symfony2,pdf-generation,twig,wkhtmltopdf
I need wkhtmltopdf on openSuSE. I have installed it via the repository. The version is 0.12.1. To render HTML with Symfony, I use the KnpSnappyBundle. By rendering a twig template, I got the following error message: The exit status code '1' says something went wrong: stderr: "wkhtmltopdf: cannot connect to...

Validation of a form before submission

php,validation,symfony2,form-submit
Using Symfony, version 2.3 and more recent, I want the user to click on a link to go to the edition page of an already existing entity and that the form which is displayed to be already validated, with each error associated to its corresponding field, i.e. I want the...

Setup VPS with a Symfony2 project from git repository

symfony2,vps
I have a: - VPS with LAMP stack - local symfony2 project (git) - bitbucket repository What do I need to do to properly setup my project in the production evironment? Folder structure/permissions? Can I simply clone the repository in the public folder? (I don't think so) P.s. I've already...

AngularJS execute some action in all application instances

angularjs,symfony2
I have AngularJS app called myApp. It has several controllers which are used in different pages (website is based on Symfony so page reloads happens sometimes). I need to execute some lines of code in every controller. how do I do that without duplicating that code?

Twig: Allow HTML, but escape script

symfony2,twig,html-sanitizing
I am investigating a possible XSS attack vector for my application. What I have: FormType with a single textarea field. Normally this field can contain html tags. Twig template that renders the data inserted. I use that form to insert the following content: <b>Some valid HTML text</b> <script type="text/javascript">alert("XSS")</script> Viewing...

Symfony2 FosUserBundle is loosing session

php,symfony2,fosuserbundle
I am using FosUserBundle to register and authenticate users in my website. But i am having troubles with it cause user session is loosen very soon. Sometimes 5 minutes, sometimes 10 minutes, and then user is redirected to the login form again, causing many users to left my website. This...

Symfony form: disable “required” for a field from Twig

php,forms,symfony2,twig
I'm trying to disable the frontend HTML5 validation for a filed in a form built in Symfony. In Twig, i use this code: {{ form_widget(form.email, {'attr': {'class': 'form-control input-lg','novalidate': 'novalidate}}) }} but the field is still considered as required. What am I doing wrong?...

Is it possible to share session between different PHP versions?

php,apache,symfony2,session,iis
I am starting an old app refactoring, I will rebuild some functionality from spaghetti code to MVC (Symfony). Plan was I will set up new IIS app, using subdomain. Now, old app is running PHP 5.3 which can't be upgraded. New app will be running on PHP 5.6. Only thing...

Why tree is invalid?

symfony2,doctrine2,tree,doctrine-extensions,stofdoctrineextensions
I have a entity that use doctrine extension, tree behaviuor, i found problems in tree and don't know it's reason. my entity: MyEntity: type: entity gedmo: tree: type: nested id: id: type: integer generator: strategy: AUTO fields: # ... lft: type: integer gedmo: - treeLeft rgt: type: integer gedmo: -...

Jms serializer @JMS\Inline() annotation overrides an actual id

php,symfony2,doctrine2,jmsserializerbundle,jms-serializer
I have product and product_detail tables in database. Every product has a product detail. class Product { /** * @var ProductDetail * @JMS\ReadOnly() * @ORM\OneToOne(targetEntity="ApiBundle\Entity\ProductDetail", mappedBy="product", cascade={"persist"}) * @JMS\Inline() */ private $detail; } I use @JMS\Inline() annotation to show only detail information of product_detail table. But when I serialize a...

Extending Twig's AppVariable

php,symfony2,twig
I've inherited a website that uses Symfony 2. The site was working fine until I ran composer to upgrade packages. It upgraded Symfony 2.6 to 2.7.1 and Twig 1.18 to 1.18.2. I now get the following error: Method "site" for object "Symfony\Bridge\Twig\AppVariable" does not exist in @Page/Page/homepage.html.twig at line 21...

Symfony one-to-one, unidirectional relation

symfony2,doctrine2
I have two entities. User and Contact. User and contact have the same property phone_number. I would like to get all contacts with user object if its exists. It is also possible that the same phone number exists in contact table but it doesn't exist in user table. Below is...

Symfony Entity query builder that checks for free spots

php,mysql,symfony2,doctrine2,dql
First off all: I know the title isn't helping, but it's the best I can think of. So I've got two entities in Symfony one is called Team and the other one Slot the Slot entity has a name, a start and end date and all that stuff. Besides that...

Unable to configure Symfony (3rd party) bundle

php,symfony2,rss
I am faily new to Symfony and I am trying to setup a third party bundle that reads RSS feeds and then insert them into database. The third party bundle I am trying to use is called rss-atom-bundle After reading the instructions I can get the RSS feeds however I...

Symfony2 Functional Testing: Is a database required or not?

php,unit-testing,symfony2,doctrine2,functional-testing
I have to write functional tests for a controller that registers a user in the application. The controller has two methods (and routes): registrationAction (route=registration) endAction (route=registration/end) Now I would like to write functional tests for those two methods. My question is: as the controller creates and persists a new...