젠드 프레임워크 2에서 렌더 뷰를 비활성화하는 방법?
ajax를 좀 사용하고 싶은데 렌더 뷰를 비활성화하기 위해 zend 프레임워크 2에서 setNoRender()와 같은 기능을 사용하는 방법을 모르겠습니다.
젠드 프레임워크 2에서 렌더링 뷰를 비활성화하는 방법?
보기를 비활성화하려면:
public function myactionAction() { // your code here ... return false; }
"return false"는 보기를 비활성화하고 레이아웃을 비활성화하지 않습니다. 왜? 허용된 유형은 다음과 같습니다.
- 모델 보기
- 배열하다
- 귀무의
그래서 "false"는 보기를 비활성화합니다.
레이아웃 및 보기를 비활성화하려면 응답 개체를 반환합니다.
public function myactionAction() { // your code here ... return $this->response; }
레이아웃을 비활성화하려면:
public function myactionAction() { // your code here ... $view = new ViewModel(); $view->setTerminal(true); return $view; }
JSON을 사용하는 경우 뷰의 화면을 봅니다.JsonStrategy
그리고 a를 돌려줍니다.JsonModel
당신의 컨트롤러로부터.이 기사 참조.
또는 다음을 반환할 수 있습니다.Response
컨트롤러에서 전체 보기 계층을 건너뜁니다.
public function testAction()
{
$response = $this->getResponse();
$response->setStatusCode(200);
$response->setContent('foo');
return $response;
}
이를 위한 적절하고 간단한 솔루션
public function testAction()
{
$data = array(
'result' => true,
'data' => array()
);
return $this->getResponse()->setContent(Json::encode($data));
}
상세정보 : http://cmyker.blogspot.com/2012/11/zend-framework-2-ajax-return-json.html
답을 찾았습니다.
그래도$this->layout()->getLayout()
새로 선택한 레이아웃의 이름/경로를 반환합니다.레이아웃은 다음 명령을 사용해도 변경되지 않습니다.
지배하에
$this->getLocator()->get('view')->layout()->setLayout('layouts/ajax.phtml');
$this->getLocator()->get('view')->layout()->setLayout('ajax');
$this->getLocator()->get('view')->layout()->disableLayout();
보기 PHTML 파일 내에서
$this->layout()->setLayout('layouts/ajax.phtml');
$this->layout()->setLayout('ajax');
$this->layout()->disableLayout();
$view = newViewModel(); $view->setTerminate(true);
...
use Zend\View\Model\JsonModel;
public function myAction() {
...
$view = new JsonModel($myArray);
$view->setTerminal(true);
return $view;
}
언급URL : https://stackoverflow.com/questions/12332843/how-to-disable-render-view-in-zend-framework-2
'programing' 카테고리의 다른 글
Gmail과 NodeJS가 있는 이메일러 없음 (0) | 2023.09.24 |
---|---|
chart.js로 색상 선을 변경할 수 없습니다. (0) | 2023.09.24 |
gcc는 리눅스 ELF에 어떤 기능을 추가합니까? (0) | 2023.09.24 |
오라클 프로시저에서 서버 출력 설정 (0) | 2023.09.24 |
팬더 데이터 프레임을 신청하기 위해 람다를 전달하는 데 문제가 있음 (0) | 2023.09.24 |