Skip to content

Instantly share code, notes, and snippets.

@videlalvaro
Created March 5, 2010 13:29
Show Gist options
  • Save videlalvaro/322718 to your computer and use it in GitHub Desktop.
Save videlalvaro/322718 to your computer and use it in GitHub Desktop.
in file: AjaxController.php
<?php
/*
Performance wise, if you just need to return a simple text to the user
and you want to save resources, you may want to avoid loading the templating
system and return the text directly the the user
*/
namespace Bundle\RabbitBundle\Controller;
use Symfony\Framework\WebBundle\Controller;
class AjaxController extends Controller
{
public function renderText($content)
{
$response = $this->container->getResponseService();
$response->setContent($content);
return $response;
}
}
//in file DashboardController.php
<?php
namespace Bundle\RabbitBundle\Controller;
use Bundle\RabbitBundle\Controller\AjaxController;
use Bundle\RabbitBundle\Model\Queue;
class DashboardController extends AjaxController
{
public function indexAction()
{
return $this->renderText(
json_encode(array(
'dashboard' => array(Queue::findForVhosts())
))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment