2014-02-17 211 views
0

我通過名爲「thisWeek」的控制器調用名爲「thisweek」的視圖。它將返回一個數組和一個對象來查看。現在我想通過ajax來改變它。所以我打電話給ajax,再次呼叫控制器「thisweek」並傳遞數據。但它無法呈現佈局。 控制器是: -通過ajax渲染布局

public function action_thisWeek(){ 
    $keywords = Input::post("keywords"); 
    $user = (Input::post("user") == "") ? -2 : Input::post("user"); 
    $direction = Input::post("direction"); 
      if(isset($_POST['from_date']) && isset($_POST['to_date'])): 
       $data['from'] = $_POST['from_date']; 
       $data['to'] = $_POST['to_date'] ; 
      else: 
       echo $data['from'] = (date('N', time()) == 1) ? date('Y-m-d') : date('Y-m-d', strtotime("last monday")); 
       echo $data['to'] = date('Y-m-d', strtotime("next sunday")); 
      endif; 
      $data["dateRange"] = $this->_createDateRangeArray($data['from'], $data['to']); 
    if(Input::get("print") && Input::get("roulatie")) { 
     $data['reservations'] = $this->getReservations(
      array("keywords" => $keywords, 
       "user" => $user, 
       "direction" => Input::get("print"), 
       "date" => Input::get("roulatie") 
      ) 
     ); 
    } else { 
     $data['reservations'] = $this->getReservations(
      array("keywords" => $keywords, 
       "user" => $user, 
       "direction" => $direction, 
       "from" => $data['from'], 
       "to" => $data['to'] 
      ) 
     );  
    } 
    if(Input::get("print")) return $this->_print($data); 
      if(!isset($_POST['from_date']) && !isset($_POST['to_date'])): 
    $this->template->title = "Reserveringen - deze week"; 
      endif; 
      $this->template->content = View::forge('admin/reservations/thisweek', $data);  
} 

Ajax調用是: -

$.ajax({ 
type: "POST", 
url: "<?php echo Uri::base(false) ?>index.php/admin/reservations/selectWeek", 
data: {to_date:week_to, from_date:week_from }, 
success: function(response){ 
     } 
     }); 

請幫助我,我怎樣才能通過Ajax呈現佈局。

回答

0

我得到了解決,我用的效應初探到HTML即我更新控制器發送到

public function action_thisWeek(){ 
    $keywords = Input::post("keywords"); 
    $user = (Input::post("user") == "") ? -2 : Input::post("user"); 
    $direction = Input::post("direction"); 
      if(isset($_POST['from_date']) && isset($_POST['to_date'])): 
       $data['from'] = $_POST['from_date']; 
       $data['to'] = $_POST['to_date'] ; 
      else: 
       echo $data['from'] = (date('N', time()) == 1) ? date('Y-m-d') : date('Y-m-d', strtotime("last monday")); 
       echo $data['to'] = date('Y-m-d', strtotime("next sunday")); 
      endif; 
      $data["dateRange"] = $this->_createDateRangeArray($data['from'], $data['to']); 
    if(Input::get("print") && Input::get("roulatie")) { 
     $data['reservations'] = $this->getReservations(
      array("keywords" => $keywords, 
       "user" => $user, 
       "direction" => Input::get("print"), 
       "date" => Input::get("roulatie") 
      ) 
     ); 
    } else { 
     $data['reservations'] = $this->getReservations(
      array("keywords" => $keywords, 
       "user" => $user, 
       "direction" => $direction, 
       "from" => $data['from'], 
       "to" => $data['to'] 
      ) 
     );  
    } 
      $weekNumber = date("W"); 
    if(Input::get("print")) return $this->_print($data); 
      if(!isset($_POST['from_date']) && !isset($_POST['to_date'])): 
    $this->template->title = "Reserveringen - ". $weekNumber ." week"; 
      $this->template->content = View::forge('admin/reservations/thisweek', $data); 
      else: 
       return Response::forge(View::forge('admin/reservations/thisweek', $data)); 
      endif; 

}