che sto di fronte a un problema davvero strano con FOSJSRoutingBundle:FOSJSRoutingBundle: "xxx percorso non esiste"
Prima di tutto, ecco la mia configurazione: sto lavorando su Symfony 2.0.23 e con JQuery, su Windows 7 64 bit con WAMP (Apache 2.4.2 e PHP 5.4.3). Ho eseguito tutte le impostazioni dal github di FOSJSRoutingBundle e ho esposto i miei percorsi (quasi tutti i problemi correlati che ho trovato su googling (sul github di FOSJSRoutingBundle, qui e su diversi forum) erano perché le persone non hanno esposto i loro percorsi, ma io provato php app/console fos: js-routing: debug e vedo i miei percorsi). Il js viene aggiunto al layout (codice del layout alla fine).
cercando di generare URL per itinerari in js, all'inizio ho voluto generare due percorsi diversi ma per test ho creato il codice js di seguito:
//Code inside this function is working
$("select").change(function() {
param=this.options[this.selectedIndex].value;
test1=Routing.generate('myBundle_step3', { myParam: param });
alert(test1);
window.location=Routing.generate('myBundle_step2');
});
//Code inside this one is also working
$('input[type="checkbox"]').change(function() {
test=Routing.generate('myBundle_step2');
}).change();
//This is not working
test=Routing.generate('myBundle_step2');
alert(test);
Con questo codice, ottengo l'errore JavaScript " Il percorso myBundle_step2 non esiste ". Anche se la prima parte funziona ancora (l'avviso mi dà il collegamento creato e il reindirizzamento va bene). Se rimuovo la seconda funzione, non ricevo più l'errore Javascript. Se nella seconda funzione sostituisco la fase 2 con la fase 3, l'errore diventa "La route myBundle_step3 non esiste". Ho provato a svuotare la cache ed eseguire l'app php app/console: installare nuovamente --symlink, ma senza risultati.
Ecco il codice di controllo corrispondente (il codice vero e proprio è un po 'lungo e non credo che sia rilevante, se si pensa così, ho potuto mettere in ogni modo:
namespace my\Bundle\Controller;
class IndividuController extends Controller
{
public function step2Action() {
Some code
}
public function step3Action($myParam) {
Some code
}
}
La configurazione routing.yml file relativo al fascio:
myBundle_step2:
pattern: /step/2
defaults: {_controller: myBundle:Individu:step2}
options:
expose: true
myBundle_step3:
pattern: /step/3/{myParam}
defaults: {_controller: myBundle:Individu:step3}
options:
expose: true
l'applicazione// file routing.yml config:
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
myBundle:
resource: "@myBundle/Resources/config/routing.yml"
prefix: /
Th informazioni rilevanti e di impaginazione:
<!-- jQuery via Google + local fallback, see h5bp.com -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"> </script>
<script>window.jQuery || document.write('<script src="js/jquery-1.7.1.min.js"><\/script>')</script>
{% javascripts 'bootstrap/js/bootstrap.js'
'bundles/fosjsrouting/js/router.js'
'bundles/crrisuaps/js/suaps.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
</body>
</html>
Risultato di php router app/console: debug (ho lasciato solo le informazioni rilevanti + Ho lasciato l'avviso variabile non definita solo nel caso, si tratta di un avviso ho avuto da quando ho aggiunto questa biblioteca, ancora le opere della biblioteca e non credo che il problema potrebbe venire da qui:
C:\wamp\www\suapsRepo\suaps>php app/console router:debug
Notice: Undefined variable: kPathUrl in C:\wamp\www\suapsRepo\suaps\vendor\html2
pdf\_class\tcpdfConfig.php on line 80
Call Stack:
0.0070 231536 1. {main}() C:\wamp\www\suapsRepo\suaps\app\console:0
0.0209 685656 2. require_once('C:\wamp\www\suapsRepo\suaps\app\bootstr
ap.php.cache') C:\wamp\www\suapsRepo\suaps\app\console:10
0.0212 701752 3. require_once('C:\wamp\www\suapsRepo\suaps\app\autoloa
d.php') C:\wamp\www\suapsRepo\suaps\app\bootstrap.php.cache:3
0.1335 2998152 4. require_once('C:\wamp\www\suapsRepo\suaps\vendor\html
2pdf\html2pdf.class.php') C:\wamp\www\suapsRepo\suaps\app\autoload.php:51
0.1379 3361792 5. require_once('C:\wamp\www\suapsRepo\suaps\vendor\html
2pdf\_class\myPdf.class.php') C:\wamp\www\suapsRepo\suaps\vendor\html2pdf\html2p
df.class.php:19
0.1385 3393792 6. require_once('C:\wamp\www\suapsRepo\suaps\vendor\html
2pdf\_class\tcpdfConfig.php') C:\wamp\www\suapsRepo\suaps\vendor\html2pdf\_class
\myPdf.class.php:12
[router] Current routes
Name Method Pattern
_assetic_55f0319 ANY /css/55f0319.css
_assetic_55f0319_0 ANY /css/55f0319_bootstrap_1.
css
_assetic_55f0319_1 ANY /css/55f0319_bootstrap-re
sponsive_2.css
_assetic_55f0319_2 ANY /css/55f0319_style_3.css
_assetic_3608a04 ANY /js/3608a04.js
_assetic_3608a04_0 ANY /js/3608a04_bootstrap_1.j
s
_assetic_3608a04_1 ANY /js/3608a04_router_2.js
_assetic_3608a04_2 ANY /js/3608a04_suaps_3.js
fos_js_routing_js ANY /js/routing.{_format}
myBundle_homepage ANY /
myBundle_inscription_etape1 ANY /inscription/etape/1
myBundle_inscription_etape2 ANY /inscription/etape/2
myBundle_inscription_etape3 ANY /inscription/etape/3/{dis
ciplineSelection}
Risultato di php fos app/console: JS-routing: debug (ho tolto la comunicazione di PHP ma succede a ogni comando che faccio btw):
C:\wamp\www\suapsRepo\suaps>php app/console fos:js-routing:debug
[router] Current routes
Name Method Pattern
crrisuapsBundle_inscription_etape2 ANY /inscription/etape/2
crrisuapsBundle_inscription_etape3 ANY /inscription/etape/3/{disciplineSelect
ion}
Edit: Inoltre, non so se è rilevante, ma quando provo 'php fos app/console: js-routing: il debug myBundle_step2' ottengo il seguente errore PHP:
[errore di eccezione] Attenzione: mancante argomento 3 per Symfony \ Bundle \ FrameworkBundle \ Command \ RouterDebugCommand: outputRoute(), chiamato in C: \ symfonyDirectory \ vendor \ bundles \ FOS \ JsRoutingBundle \ Command \ RouterDebugExposedCommand.php sulla riga 62 e definito in C: \ serverDirectory \ vendor \ symfony \ src \ Symfony \ Bundle \ FrameworkBundle \ Command \ RouterDebugCommand.php riga 98
Puoi mostrarci il tuo controller di queste due azioni con la configurazione annotazioni/xml del tuo routing? – stedekay
Ho modificato e aggiunto tutto il routing.yml + il codice del controller. – MisterJ
Hai aggiunto il js al tuo layout? Vedi [qui] (https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/blob/master/Resources/doc/README.markdown#usage) – Erioch