16
votes
1answer
2k views

Managing common javascript dependencies in Symfony 2

I would like to know what is the standard best practice for dealing with common JavaScript (and even CSS) dependencies across several Symfony 2 bundles. According to the Book on the official Symfony ...
14
votes
5answers
21k views

How can i send json response in symfony2 controller

I am using jQuery to edit my form which is built in Symfony. I am showing the form in jQuery dialog and then submitting it. Data is entering correctly in database. But I don't know whether I need ...
10
votes
3answers
12k views

Generating routes in javascript with Twig and Symfony2

Quite odd problem, sorry for asking, i'm quite new to Symfony/Twig. My route requires a mandatory region_id paramenter: ajax_provinces_by_region: pattern: /ajax/region/{region_id}/provinces ...
7
votes
2answers
3k views

how to use Backbone.js with the Symfony framework and or Apache Thrift

I recently installed a web app which use Symfony2 framework and Apache Thrift. Now I would like to make backbone usable in Symfony2 framework. My question is about Backbone.sync. How can I ...
6
votes
2answers
1k views

symfony 2 equivalent for url_for() function in symfony 1

In Symfony 1 we can access an action in template page as for example url_for('modulename/actionname') without writing anything in routing.yml. how is this possible in Symfony2?,that is if i have to ...
5
votes
2answers
10k views

Using javascript in Symfony2/Twig

I have a view called contact.html.twig. It has a form with some textfields. I want to use javascript to validate that none of the fields are empty, as well as some other rules. But I do not know where ...
5
votes
4answers
2k views

Browser aborting Ajax requests sporadically without returning any errors [duplicate]

In my project (PHP with Symfony 2) I do a lot of Ajax requests in every page. I'm having a lot of problems with them, because it looks like browsers (tested in Google Chrome and Firefox) are aborting ...
5
votes
2answers
8k views

Using Twig for dynamic Javascript files

I'm working on a kind of dashboard mini site that has blocks with a certain functionality. Using symfony2 I have a dedicated route /instagram that gets an html fragment that shows all the images taken ...
5
votes
2answers
476 views

how to add remove and add button with lines using jquery?

i want to add remove and add buttons with the fields on row hover like this. but my dynamic fields generate on button click which changes i can do for above link design? here is my code: <tr> ...
5
votes
4answers
2k views

Symfony2 multiple forms in different JQuery UI tabs but single page

I'm facing a problem that I can summarize as it follows: I have a TWIG template page like this (reg.html.twig): {% extends "::base.html.twig" %} {% block body %} <ul class="tabs"> <li ...
5
votes
1answer
1k views

Sharing Symfony2 validation rules with backbone.js or javascript in general?

Whould be possible to expose Symfony2 validation rules (for a given Entity)? I can't find nothing like this. I'm trying to do client-side validation (using backbone.js) with a DRY approach. Something ...
4
votes
3answers
971 views

How to send javascripts to the bottom? (in symfony 2)

I want to create views that can by themselves print some html code, and at the same time, send javascript code to the bottom, without extending the layout The idea is that I have a layout, then the ...
4
votes
3answers
2k views

How to Use Assetic for requireJs

I am trying to use require.js in synfony2 project. Here the code in the main twig file: <script data-main="{{ asset('bundles/web/js/main.js') }}" src="{{ ...
3
votes
2answers
4k views

Use Javascript to access a variable passed through Twig

I have a controller that passes an array to a twig template, which I want to use in a script written on that page. How would I go about doing that? I've tried this in my .twig template: ...
3
votes
1answer
932 views

Symfony 2 - Assetic Javascript compression causing errors

I'm trying to put a Symfony 2 app in production mode. It all runs fine except for the fact that the compressed single javascript file causes errors and makes the site unable to render correctly. I ...
3
votes
3answers
292 views

How can i simulate REST post request with json data in browser

I have the web application where the frontend is in ExtJS and backend is in PHP. The forms are build in Extjs and its making PUT and POST request to server for saving data. The josn data is posted ...
3
votes
1answer
2k views

How to validate Symfony 2 form on client side (javascript)

I'm new to symfony 2 and i'm trying to build a standard form which should be validated by the server and by the navigator. Server-side validation works fine with assertions like @Assert\... but i ...
3
votes
1answer
82 views

how to detect screen size or mobile/desktop using twig

I am currently using twig as my templating engine and I wanted to load different url of an image when the site is loaded using mobile vs desktop. Is there an easy way to do this? So I wanted to do ...
3
votes
1answer
4k views

Symfony2 and jquery ajax

I am developing an application using Symfony2 and Jquery as a JavaScript FW. I am using Twig for the templates. I render a template from the controller and after making a selection using the cursor in ...
3
votes
2answers
3k views

Symfony 2 append Javascripts, just one request

I have a layout.html.twig with: {% block js %} {% javascripts 'Resources/public/js/jquery/jquery-1.7.1.min.js' 'Resources/public/js/jquery/jquery.namespace.js' ...
3
votes
3answers
2k views

Symfony2 Ajax and Jquery

I am developing an application using Symfony2 and twig for the templates. I am also using ajax. This is part of my code in my controller: public function testuaanotatuAction(Request $request) ...
3
votes
1answer
537 views

Using Twig as an Assetic filter for JavaScript in Symfony2

Is there a way to use Twig as an Assetic filter? What I want to do is have Twig parse my JavaScript files as Twig templates, and then pass them to Assetic so that they get combined and minified in ...
2
votes
2answers
1k views

Which javascript MVC framework stacks better with Symfony 2?

Many good ones are mentioned here but I'd like to know which one stacks better with Symfony 2.
2
votes
1answer
550 views

How can I debug a failing Capifony deploy due to assetic:dump process time time out?

$ cap deploy is failing and here is the snippet from the failed output * executing "cd /var/www/site/prod/releases/20120831164520 && php app/console assetic:dump web --env=prod ...
2
votes
2answers
1k views

Executing javascript after twig template has loaded

I'm using Symfony 2 and I need to execute a javascript just after the following twig template has loaded: <div data-role="dialog"> <div data-role="header"> <h1>Input ...
2
votes
1answer
1k views

Symfony2: how to choose Javascript files load order?

I am using jQuery in my Symfony2 application and I have a "ReferenceError: jQuery is not defined" error. I think changing Javascript file load order could fix this. How could I force to load jQuery ...
2
votes
2answers
1k views

Symfony 2 translations in external js file

I want to put some translations to functions in external Java Script file. It is possible to parse js file e.g. like Twig template?
2
votes
3answers
31 views

Error while trying to use a parameter in function

Working on symfony, I'm developping the following javascript function using bootbox : function ask_delete(id) { bootbox.confirm("Are you sure?", function(result) { if(result) { ...
2
votes
3answers
698 views

Symfony and assets usage at runtime with Javascript

As explained in the official Symfony2 docs, in a Twig template one can link to an asset as follows: <img src="{{ asset('images/logo.png') }}" alt="My logo" /> which will render the right path ...
2
votes
1answer
1k views

twig code in js file

Using symfony2 with twig templates, I normally use js embedded inside the *html.twig file to dinamize yet more the pages. What if I have external JS files attached to my page? How could I introduce ...
2
votes
2answers
2k views

JavaScript validation for Symfony 2 forms

Does exist Bundle which allows generate JavaScript equivalent to validators of Symfony 2 forms? I am looking for something similar to ...
2
votes
1answer
77 views

Where to place images in assetic when references from javascript

I am using assetic in Symfony 2. I have JavaScript and CSS loaded using assetic. I need to reference some images in one of my JS files. I am new to assetic, and cannot find any documentation on ...
2
votes
1answer
149 views

Including Zepto or jQuery at runtime in Symfony2

I am attempting to incorporate Foundation framework in Symfony2. I copied all the css/js assets in the app/Resources folder and am able to reference them. However there is one part which is not ...
2
votes
2answers
2k views

Using Zurb Foundation and Symfony2

In my Symfony2 application, I am using the Zurb Foundation to built my layout on. This keeps giving me headaches... the css works pretty well but the js often does not work. The files are loaded and ...
2
votes
2answers
472 views

Proper way of generating dynamic javascript in Symfony 2?

I need to generate a dynamic JSON object using some twig function like asset and translate. I'd like to put it in an external settings.js file. I may use include 'settings.js.twig' and put the ...
2
votes
1answer
81 views

Embed collection of form

I'm stuck with an embed collection of form. I have a Holiday form consisting of three fields : a name, a begin and an end. Note that begin and end are managed by Bootstrap date-time picker Then I ...
2
votes
1answer
213 views

XSS Basic Understanding

I'm using Symfony2 / Twig / Doctrine. I'm looking at security on my site and in particular preventing XSS attacks, but I can't see what more I can do. Persistent I use Doctrine and always ensure I ...
2
votes
1answer
433 views

Bazinga Expose Translation Bundle does not translate

I have a DOM element that is created via ajax something like this: $('.inner').append('<p>Salva Foto</p>'); my Twig is composed {% javascripts ***my js*** %} <script src="{{ ...
2
votes
1answer
254 views

Where should I store my Jasmine files in a Symfony project?

What is the best place to put the Jasmine files (libs, specs, SpecRunner.html) in a symfony project? I would make in this way: the jasmine libs in web/vendor/js the spec files in ...
2
votes
1answer
1k views

Symfony2: JavaScript doesn't work on Prod environment

In Dev enviroment it works perfectly, but when I switch to Prod it doesn't do anything. It looks like it doesn't attach the event listeners (when I inspect elements with Chrome, no event listener is ...
2
votes
1answer
361 views

symfony get form attributes

I know that it is dumb question to ask but I need to know can I get form widget attributes through PHP I mean not a value but id, class or even parent or child. If I set them. <label name = '{{ ...
2
votes
1answer
44 views

Symfony2 :: Add assets when a custom formtype is loaded

I've created a service for loading a custom form-type. But is it possible whenever I call this service, that automatically some javascript is autmaticlly loaded in mine block 'footer_javascripts' ? ...
2
votes
0answers
72 views

Assetic javascripts creating empty file from a non-empty source (inside bundle)

I am using Assetic within a twig template to specify 2 JS files to utilize from my bundle { % javascripts '@JiraExtendedReportsBundle/Resources/public/js/jquery-2.0.3.min.js' ...
2
votes
1answer
122 views

Include Javascript in Symfony2 form widgets

I have created my own little Symfony2 form type. For this to work properly, I need to include a js library. While that was a simple task when using this new form type in a single web application, it ...
2
votes
1answer
185 views

how to get form id from ajax and set it in click function in symfony2

i want to store id in global variable and then store this id for form edit here is my xml request: if($request->isXmlHttpRequest()) { $response = new Response(); $output = ...
2
votes
3answers
55 views

Write link to images in .js file - Symfony2

I'm using Symfony2 and I have some links to images in my .js file - like this: $(this).attr('src', 'img/icons/black/icon1.png'); Of course they don't work this way :( How should I set them? At ...
2
votes
2answers
2k views

FOSJSRoutingBundle : “Route xxx does not exist”

I'm facing a really weird problem with FOSJSRoutingBundle : First of all, here is my configuration : I'm working on Symfony 2.0.23 and with JQuery, on Windows 7 64 bits with a WAMP (Apache 2.4.2 and ...
2
votes
0answers
257 views

Symfony2, periodic JS failure with FOS Routing

Sometimes my JS fails to load dynamically via Symfony2, the URLs look like; /app_dev.php/js/d5fb045_part_1_main_4.js Looking at this URL using dev tools shows that the JS is returning; Fatal ...
2
votes
0answers
158 views

Sprocketsfilter in assetic - requirements and example [closed]

I'm working with Symfony 2 with Twig and assetic file manager. I have high number of javascript files that have many dependencies. (Javascript prototypal inheritance) I saw sprockets in action, and I ...
2
votes
1answer
974 views

Twig: comments in {% javascripts %}

I have a situation like this in my twig file: {% javascripts 'js/functions.js' 'js/plugins.js' 'js/editor.js' 'js/calendar.js' %} [...] And I would love to comment some scripts out ...