Symfony doc sagt:
Symfony2: Session Globale Variablen in PHP Template
During each request, Symfony2 will set a global template variable app in both Twig and PHP template engines by default. The app variable is a GlobalVariables instance which will give you access to some application specific variables automatically:
app.security - The security context.
app.user - The current user object.
app.request - The request object.
app.session - The session object.
app.environment - The current environment (dev, prod, etc).
app.debug - True if in debug mode. False otherwise.
Beispiele:
In Zweig: {{ app.request.method }}
In PHP: echo $app->getRequest()->getMethod()
In Zweig: {{ app.user.username }}
Aber für das Session-Objekt:
In Zweig:
In PHP: // I don't know, do you know how to call it?
Ich habe versucht: $session = $app->getSession('uid');
aber wenn ich versuche, zu einer Datenbank speichern sie es sagt mir:
Catchable Fatal Error: Object of class Symfony\Component\HttpFoundation\Session could not be converted to string in C:\wamp\www...
Es gibt einen Mangel an Ressourcen, wenn es um PHP-Vorlagen kommt, aber in meinem Fall kann ich nicht wechseln aus irgendwelchen Gründen.
Die Frage mit anderen Worten, was ist das Äquivalent in PHP Templating von:
{{ app.session.varname }}
?
Hey, spottest du mich? :) Toller Typ, der es geschafft hat, danke eine Tonne für deine Antwort. –
Kein Spott beabsichtigt. Ich hatte Ihre Frage auskommentiert und positioniert, um klarzustellen, welches Problem angesprochen wurde. Dann ging @ Daniel Ribereiro rein und redigierte Sachen. Keine Ahnung warum, aber es hat die Absicht durcheinander gebracht. – Cerad
Mein schlechtes, es war mit guten Absichten. –