J'ai envie d'afficher mon variable dans le twig sur symfony, ensuite j'utilise aussi l'angularjs mais quand j'affiche mon variable sur twig, je ne trouve rien. Enfin, j'ai vu que le problème c'est que l'affichage de variable en symfony et angularjs est de même principe.

Aide-moi s'il vous plaît !

3 réponses


Tu veux pas un café aussi ? Commment veux tu qu'on t'aide sans le code ?

Mimason'
Auteur

Voici mes codes :

Twig
<div class="table-responsive">
            <div class="row">
                <table ng-table="tableParams" ng-app="myApp" ng-controller="FormController" show-filter="true" template-pagination="pager-template" class="table table-bordered table-striped">
                    <thead class="text-center">
                        <tr>
                            <th ng-repeat="column in columns track by $index"
                                ng-show="column.visible"
                                ng-click="sortGrid(column)"
                                class="text-center sortable col-{{ column.index }}">
                                {{ column.title }}
                                &nbsp;
                                <span ng-if="column.sortable" class="fa fa-chevron-down"></span>
                            </th>
                            <th class="col-save">Actions</th>
                        </tr>

                        <div >
                        {{ form_start(form, {'action': path('lexik_translation_new'), 'method': 'POST'}) }}
                        <tr>
                            <th>
                                <span class="text-danger">
                                    {{ form_errors(form.domain) }}
                                </span>
                               {{ form_widget(form.domain, { 'attr': {'class': 'form-control', 'ng-model': 'formData.domain'} }) }}
                            </th>
                            <th>
                                <span class="text-danger">{{ form_errors(form.key) }}</span>
                                {{ form_widget(form.key, { 'attr': {'class': 'form-control'} }) }}
                            </th>
                            {% for translation in form.translations %}
                            <th>
                                <span class="text-danger">
                                    {{ form_errors(translation.content) }}
                                </span>
                                {{ form_widget(translation.content, { 'attr': {'class': 'form-control'} }) }}
                                {{ form_widget(translation.locale) }}
                            </th>
                            {% endfor %}
                            <th>
                                {{ form_widget(form.save, { 'attr': {'id': 'trans-unit-submit', 'name': 'trans-unit-submit', 'class': 'btn btn-theme-blue'} }) }}

                                {{ form_widget(form.save_add, { 'attr': {'id': 'trans-unit-submit-2', 'name': 'trans-unit-submit-2', 'class': 'btn btn-theme-blue d-none'} }) }}
                            </th>
                        </tr>
                        {{ form_end(form) }}

                    </thead>
                    <tbody>
                        <tr editable-row ng-repeat="translation in $data track by $index" translation="translation" columns="columns" edit-type="editType"></tr>
                    </tbody>
                </table>

                <div class="alert alert-info" role="alert" ng-if="tableParams.total() < 1">
                    {{ labels.noTranslations }}
                </div>

            </div>
        </div>
Controller :
/**
     * Display the translation grid.
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function gridAction(Request $request)
    {
        $tokens = null;
        if ($this->container->getParameter('lexik_translation.dev_tools.enable')) {
            $tokens = $this->get('lexik_translation.token_finder')->find();
        }

        $handler = $this->get('lexik_translation.form.handler.trans_unit');
        $form = $this->createForm(TransUnitType::class, $handler->createFormData(), $handler->getFormOptions());

        if ($handler->process($form, $request)) {
            $message = $this->get('translator')->trans('translations.successfully_added', array(), 'LexikTranslationBundle');

            $this->get('session')->getFlashBag()->add('success', $message);

            $redirectUrl = $form->get('save_add')->isClicked() ? 'lexik_translation_new' : 'lexik_translation_grid';

            return $this->redirect($this->generateUrl($redirectUrl));
        }

        return $this->render('@LexikTranslation/Translation/grid.html.twig', [

            'layout'         => $this->container->getParameter('lexik_translation.base_layout'),
            'inputType'      => $this->container->getParameter('lexik_translation.grid_input_type'),
            'autoCacheClean' => $this->container->getParameter('lexik_translation.auto_cache_clean'),
            'toggleSimilar'  => $this->container->getParameter('lexik_translation.grid_toggle_similar'),
            'locales'        => $this->getManagedLocales(),
            'tokens'         => $tokens,
            'form'   => $form->createView(),
        ]);
    }
Angularjs :
var app = angular.module('myApp', []);
        app.controller('FormController', function ($scope, $http) {
            var formData = {
                domain: "default",
                key: "default",
                translation.content: "default",
                translation.locale: "default",
            };

            $scope.save = function() {
                formData = $scope.form;
            };

            $scope.submitForm = function() {
                console.log("posting data....");
                formData = $scope.form;
                console.log(formData);
            };
        };

alors que cherches tu à faire exactement ?