what i need
- i just want to implement session in symfony.
here is what i tried
/src/Acme/bundlename/Twig
Acmeextension.php
public function getFunctions() { return array( 'count' => new \Twig_Function_Method($this, 'count'), ); } public function count() { session_start(); if(isset($_SESSION["count"])) { $accesses = $_SESSION["count"] + 1; } else { $accesses = 1; } $_SESSION["count"] = $accesses; return $accesses; }here is the code of twig:
function callback() { var page = {{ count}}; if (page >4) { alert("limit exceeded"); } else { alert("ok"); } } callback();calling in twig {{ count }}- i just want calculate pageviews.
- i used script in twig so that i if there is page view are more then 4 then show alert message.
- i have used symfony custom functions so that $SESSION in symfony.
- i have implemented this code in core Php its working fine.
i have refer the link Passing Session to TWIG template.
custom Twig Extension http://symfony.com/doc/current/cookbook/templating/twig_extension.html
Problem
- im not Gettig any alert in when i reload the page.
- please tell me where im wrong , any suggestion are most welcome.