2012-10-24 7 views
0

하이 뷰에 데이터를 렌더링, 다음 코드는 popularAction 컨트롤러젠드 JSON은 내가 젠드 프레임 워크 애플리케이션을

public function popularAction() 
    { 
     $type = $this->_getParam('ref',1); 
     if($type == 'reviews'){ 
     $businessReviewMapper = new Application_Model_Mapper_BusinessReviewsMapper(); 
     $result = $businessReviewMapper->getTotalVote(); 

     $rotd = $businessReviewMapper->getROTD($result['review_id']); 
     $rotd[0]['u_img'] = $this->view->getLoginUserImage($rotd[0]['social_id'],$rotd[0]['login_type'],null,null,square); 
     $rotd[0]['rating'] = $this->view->getRatingImg($rotd[0]['rating']); 
     $rotd[0]['business_name_url'] = preg_replace("![^a-z0-9]+!i","-", $rotd[0]['business_name']);    
     $this->render('reviews'); 
     $this->_helper->json($rotd); 



     } elseif($type == 'openings') { 
      $this->view->text = "New Openings"; 

     } else { 
      $this->_helper->redirector('index', 'index', 'default'); 
     } 

    } 

있습니다. 이제 템플릿 자체 내부 아약스 다음과 같은 데이터에 대한 요청이 : 젠드 DB 모델에 의해 반환되는

function getPopular() 
{ 
    var count=1; 
    $.ajax({ 
     url:"<?=$this->baseUrl('business/popular?ref=reviews')?>", 
     data:{'count':count}, 
     dataType:"json" 
     type:"POST", 
     success:function(data){ 
      alert('ok') 
     } 
    }); 

불행하게도 $this->_helper->json($rotd);가 reviews.phtml에 데이터를 전달하지 않지만, 디스플레이 JSON 데이터는 어디에서 잘못 될 수있는 당신의 목표는, Ajax 요청에로 .phtml 파일 대신 JSON을 보내도록하는 경우 감사

답변

1

, 이것은 구현하려고?

if ($this->getRequest()->isXmlHttpRequest()) { 
     if ($this->getRequest()-isPost()) { 
      $this->_helper->json($rotd); 
     } 
    } 

요청이있는 경우이 부분 검사를 할 수 있습니다 그것을 호출 : 아약스 기반 ..