Is it possible to store data in one private variable of a controller (Symfony2)?
One example:
/**
* Class CatsController
*
* @Route("cats")
* @Cache(expires="+600 seconds", public=true)
* @package oTeuGato\AppBundle\Controller
*/
class CatsController extends Controller {
/**
* @var $advertisements Advertisement[]
*/
private $advertisements;
/**
* Index advertisements page
*
* @Route("", name="oTeuGato_Cats")
* @Method("GET")
* @return Response
*/
public function indexAction()
{
$this->advertisements = ....(Use a service for gets advertisements)
}
/**
* Index advertisements by page
*
* @Route("/{id}", requirements={"id" = "\d+"}, defaults={"id" = 1}, name="oTeuGato_Cats_ByPage")
* @Method("GET")
* @return Response
*/
public function indexByPageAction(){
....
}
In this example whenever someone calls the URL: cats/1 in the controller I need them to have all advertisements of the previously called method (/cats).
Is this possible?
Note: I enabled the cache in the app.php file and app_dev.php.
Thanks for help and sorry for my English ;)