ajax 요청을 현재 컨트롤러의 다른 Action 메소드로 전달해야합니다. Forward 플러그인을 사용하지만 작동하지 않습니다. 앞으로 플러그인을 사용하는 방법에 대한 설명서의 예제가있다 :ZF2 : 컨트롤러의 전달 플러그인이 작동하지 않습니다. 어떻게 작동 시키는가?
$foo = $this->forward()->dispatch('foo', array('action' => 'process'));
return array(
'somekey' => $somevalue,
'foo' => $foo,
);
내 코드 :
// From Ajax on the page. I apply to the indexAction of FooController,
// I use RegEx route
xhr.open('get', '/fooindex', true);
// My Controller
namespace Foo\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
// I extend the AbstractActionController, the manual says it's important for the Forward Plugin to work
class FooController extends AbstractActionController {
// This is the action I send my request from Ajax
public function indexAction() {
// if the request if Ajax request I forward the run to the nextAction method
if ($this->getRequest()->isXmlHttpRequest()) {
// I do as manual says
$rs = $this->forward()->dispatch('FooController', array('action' => 'next'));
}
}
public function nextAction() {
// And I just want to stop here to see that the Forward Plugin works
// But control doesn't reach here
exit('nextAction');
}
}
내가 콘솔에서 얻을 오류는 다음과 같습니다
GET http://test.localhost/fooindex 500 (Internal Server Error)
경우 I 앞으로 모든 것을 잘 사용하지 마십시오. 요청은 indexAction
에 그대로 있습니다. 전달에서만 오류가 발생합니다.
From the manual, about The Forward Plugin :
앞으로 플러그인이 작동하려면, 그것은 ServiceLocatorAware해야 호출하는 컨트롤러; 그렇지 않으면, 플러그인은 요청 된 컨트롤러의 구성되고 삽입 된 인스턴스 을 검색 할 수 없습니다.
From the manual, about Available Controllers : 상기 각 인터페이스 구현
중복성의 교훈; 자주하지 않으려합니다. 따라서 시작하기 위해 확장 할 수있는 두 개의 추상적 인 기본 컨트롤러를 개발했습니다.
AbstractActionController는 다음 각 인터페이스 구현 :
젠드 \ STDLIB \ DispatchableInterface 젠드 \ MVC \ InjectApplicationEventInterface 젠드 \ ServiceManager에 \ ServiceLocatorAwareInterface 젠드 \ 개의 EventManager \ EventManagerAwareInterface을
그래서 내 FooController
는 AbstractActionController
를 확장 , 이는 ServiceLocatorAwareInterface
을 구현하므로 전달이 작동해야하지만 그렇지 않습니다. 내가 놓친 게 무엇입니까? 어떻게 작동 시키는가?