programing

젠드 프레임워크 2에서 렌더 뷰를 비활성화하는 방법?

codeshow 2023. 9. 24. 13:10
반응형

젠드 프레임워크 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

반응형