-- Dan Rossi <[EMAIL PROTECTED]> wrote
(on Wednesday, 22 August 2007, 03:29 PM +1000):
> Hi there, i've run into a problem specifically with implementing ajax
> into a system im building. Basically I'm using the Jquery Ajax framework
> to call controllers and actions in the background into a main index
> template rather than linking directly in the nav. The issue here is, I
> can only render the inner template on the controller / action being
> called or else it will redisplay the main template.
>
> Is there any such Ajax integration as yet, so a view can be changed for
> an ajax view and then a view can be normal with the index template on a
> normal view ?
>
> The other question here is, Ive been using PEAR's Html_Ajax for quite
> some time, which I use it as a proxy to Ajax Service classes, which then
> call the class directly to output rather than simply calling the page
> in the background which runs the entire controller process. Is there
> such a thing implemented yet at all ?
I'm preparing a proposal for a feature like this. In the meantime, I
have the following action helper I use:
class Phly_Helper_Ajaxable extends Zend_View_Action_Helper_Abstract
{
public function direct()
{
$controller = $this->getActionController();
$request = $controller->getRequest();
if ($request->isXmlHttpRequest()
&& isset($controller->ajaxable)
&& is_array($controller->ajaxable)
&& in_array($request->getActionName(), $controller->ajaxable))
{
$viewRenderer =
Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer');
$viewRenderer->setViewSuffix('ajax.phtml');
// logic to suppress main layout
}
}
}
For it to work, you simply define an array of actions in your controller
that are ajaxable, and assign it to the public property 'ajaxable'. You
then call the helper in your action controller:
class FooController extends Zend_Controller_Action
{
// actions that can be called via ajax
public $ajaxable = array('bar', 'baz');
public fuction preDispatch()
{
$this->_helper->ajaxable();
}
}
Then all you need to do is create different view scripts for ajaxable
actions. In my example here, you'd have both 'bar.phtml' and
'bar.ajax.phtml'; same with the 'baz' action.
Note the commented line in the helper; until we have a layout solution
in place (expected for 1.1.0), you'll need to do that logic yourself.
Additionally, if you want to use a different view script suffix, you
could set it there as well.
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/