2017-01-31 8 views
0

분명히 CodeIgniter에 대한 이전 경험이 전혀 없습니다.CodeIgniter 버전 업데이트 - 빈 배열을 생성하는 쿼리 작성기의 limit()

최근에 CI 버전이 최신 버전으로 업데이트되고 일부 루프에 아무것도 표시되지 않는 이전 웹 사이트가 할당되었습니다. 이 문제는 limit() 함수가 사용되는 쿼리 작성기 행으로 시작됩니다. Home.php 컨트롤러

__construct() 기능을 수행합니다

$this->load->orm('db_et_comu_news', 'news'); 

이 후 index() 기능이 있습니다

$this->_data['news'] = $this->news->where('status',1)->where('id_et_cat_comu_news',2)->order_by('data','DESC')->limit(7)->find_all(); 

이 과거 CI 버전에서 근무하고 완벽하게 작동 배열을 반환 결과가 나오지만 업데이트가 끝나면 빈 배열이됩니다. 원하는대로,

$this->_data['news'] = $this->news->where('status',1)->where('id_et_cat_comu_news',2)->order_by('data','DESC')->find_all(); 

쿼리가 좋은 건강한 배열을 반환하지만 7 내 행을 제한하지 :이처럼 만들기 쿼리에서 limit()를 제거합니다.

CI 3.1.3 설명서를 확인한 결과 이 올바르게 적용되어야합니다.이 올바르게 적용됩니다. 누구든지 문제를 발견하도록 도와 줄 수 있습니까?

답변

1

컨트롤러 코드를 다음으로 바꾸십시오.

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Home extends CI_Controller 
{ 
    function __construct() { 
     parent::__construct(); 
    } 

    function index() 
    { 
     $data['news'] = $this->news(); 

     if(!empty($data['news'])) 
     { 
      foreach($data['news'] as $objects) 
      { 
      echo $objects->data; 
      } 
     } 

    } 

    function news() 
    { 
     $query = $this 
       ->db 
       ->select('*') 
       ->from('db_et_comu_news') 
       ->where('status',1) 
       ->where('id_et_cat_comu_news',"2") 
       ->order_by("data", "DESC") 
       ->limit(7) 
       ->get(); 
     if($query->num_rows()>0) 
     { 
      return $query->result(); // return an array of objects 
     } 
     else 
     { 
      return null; 
     } 
    } 

} 
+0

나는, 내가 재확인 도와 주셔서 감사합니다 너무 자신에 의해 결론에 오기를 결국 나는 지역의 톤이 작업을 수행해야하기 때문에 나는 간단한 대답을 사용할 수 있습니다 희망, 그것은 정답의 상점 것 같다 이 – XuxuBelezA