I've done exactly what you have with Zend FW and Ajax. i.e. calling
regular controller/action methods, mainly because the functionality
between the Ajax request and a regular request is almost the same.

I don't know if there's a way to tell the controller not to
auto-render a view, so instead I just put an "exit" statement at the
end of the Ajax code. That way no attempt is made to render a view.
This probably isn't best practice, but it works :)

Cheers,
Chris


2008/11/3 Aaron Cooper <[EMAIL PROTECTED]>:
> Hi all,
>
> I'm working on an integration of Zend FW 1.6 and ExtJS 2 and having a bit of
> trouble getting my head around just how AJAX should interact with an MVC
> pattern (if it should at all)
>
> Basically, I have an ExtJS login box that I am testing for this purpose. The
> call seems to be correctly sent to the right mehtod, but because by default
> the framework attempts to display a View file of the same name, this is
> failing. All I want is the method to output data in JSON format for ExtJS to
> work with.
>
> Zend Code:
> <?php
>
>   class IndexController extends Zend_Controller_Action
>   {
>
>     public function init()
>     {
>         $contextSwitch = $this->_helper->getHelper('contextSwitch');
>         $contextSwitch->addActionContext('list', 'xml')
>                       ->initContext();
>     }
>
>     function indexAction()
>     {
>       $this->view->title = "My Albums";
>       $albums = new Albums();
>       $this->view->albums = $albums->fetchAll();
>     }
>
>     function ajaxLoginAction()
>     {
>      // Do Login Actions
>      echo "{success: true}";
>
>     }
>
>   }
>
> Error from Firebug:
>
> <br />
>
> <b>Fatal error</b>:  Uncaught exception 'Zend_View_Exception' with message
> 'script 'index/ajax-login
>
> .phtml' not found in path (..\application\views\scripts\)' in
> C:\wamp\www\zend\library\Zend\View\Abstract
>
> .php:875
>
> Am I even going about this right? Or is it best to separate these actions
> from the MVC framework and just use my own scripts in a separate directory?
> There's next to no info on AJAX stuff online, and almost zero on ExtJS
> (which shouldn't really matter anyway).
>
> Cheers
>
> Aaron
>
> >
>



-- 
Chris Hope
The Electric Toolbox Ltd

Email: [EMAIL PROTECTED]
Web: www.electrictoolbox.com
Phone: +64 9 522 9531
Mobile: +64 21 866 529

--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to