Skip to content

Instantly share code, notes, and snippets.

@corleonis
Created December 11, 2012 16:59
Show Gist options
  • Save corleonis/4260280 to your computer and use it in GitHub Desktop.
Save corleonis/4260280 to your computer and use it in GitHub Desktop.
Switch context with ZF - JSON/HTML
<?php
class Bruegelbe_InfocusController extends Herder_Controller_Action
{
public function init() {
$context = $this->_helper->contextSwitch();
$context->addActionContext('contentItems', array('json'))
->initContext();
}
public function contentItemsAction() {
$tables = Bruegel_Model_Infocus::getTables();
$table = $this->_getParam('table');
$class = $tables[$table];
$model = new $class();
$data = null;
if(isset($model) && is_object($model)) {
if($table =='tx_bruegel_people') {
$order ='name';
} else {
$order ='title';
}
$data = $model->getAll(array(), null, $order);
}
$this->view->data = Bruegel_Model_Infocus::buildArray($data);
if($this->_request->isXmlHttpRequest()) {
$this->_helper->contextSwitch()->initContext('json');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment