I have following code in my bootstrap file:
PHP Code:
...
/**
* Setup controller
*/
$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory('../application/default/controllers');
$controller->throwExceptions(true); // should be turned on in development time
/**
* Set Zend Layout
*/
Zend_Layout::startMvc();
//Zend_Layout::getMvcInstance()->setViewSuffix('tpl');
/**
* Check ajax requests
*/
Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_AjaxContext());
...
I've made AjaxController:
PHP Code:
<?php
/**
* AjaxController
*
* @author
* @version
*/
require_once 'Zend/Controller/Action.php';
require_once 'Zend/Json.php';
class AjaxController extends Zend_Controller_Action
{
public $ajaxable = array('convert'=>array('json'));
function init()
{
$this->_helper->viewRenderer->setNoRender();
//$this->_helper->ajaxContext->initContext('json');
}
public function preDispatch()
{
$this->_helper->viewRenderer->setNoRender();
$this->_request->setParam('format', 'json');
$this->_helper->ajaxContext()->initContext();
}
/**
* The default action - show the home page
*/
public function indexAction ()
{
}
public function convertAction()
{
//file_put_contents('C:/sasa.txt', $this->getRequest('text'));
file_put_contents('C:/sasa.txt', var_export($this->getRequest('text'), true));
//var_dump($_POST);
$jsonData = Zend_Json::encode($_POST);
echo $jsonData;
//$this->response->appendBody($jsonData);
//$this->getResponse()->setBody($jsonData);
}
}
And whatever I response in convertAction, I get : '[]' - empty brackets in my response, and that makes invalid json object on the client! So I can't eval it.
Also have a problem that when I have ajax action, I cannot get :
PHP Code:
$this->getRequest('text');
Even if $_POST['text'] is properly set.
What is the problem?