I used the $this->_request->isXmlHttpRequest() to determine if request is
made with ajax. This works with jQuery. Then I have made following rows to
be called automatically, when $this->_request->isXmlHttpRequest() is true.

$this->getFrontController()->setParam('noViewRenderer', true);
$this->getResponse()->setHeader('Content-type', 'text/html');

Now I can decide freely what kind of response to send to ajax-function.
Json, html, xml...

I can use normally $this->view object and render different view script when
called from ajax.

example from some action method:

when this is called from ajax, viewRenderer won't auto-render (made in
preDispatch).
I change the view script to be rendered at the bottom of method (when called
from ajax).

If this action is called directly from browser, it will auto-render view
script with default filename (/view/scripts/{controller}/{action}.phtml

public function detailAction()
    {
        $this->view->title              = "File_ImageController::detailAction";

        $this->view->src                = "/image/src/$this->_filename";

        $this->view->width              = $this->_width;

        $this->view->height             = $this->_height;

        $this->view->download   = "/download/$this->_filename";

        
        if ($this->_request->isXmlHttpRequest())
        {
                        $this->render('detail-ajax-version'); // 
        }
    }

I hope this helps you or somebody...

ZF rocks!
-- 
View this message in context: 
http://www.nabble.com/Changing-views-specific-for-ajax-tf4309496s16154.html#a12269524
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to