2011-08-02 5 views
0
안녕하세요이 연령대에 일을 얻기 위해 노력하고

,CakePHP의 알 수없는 인덱스 문제

나는 거래 컨트롤러

<?php 
class DealsController extends AppController { 

    var $name = 'Deals'; 
    var $helpers = array('HTML', 'Javascript', 'Form', 'Time', 'Ajax'); 
    var $components = array('RequestHandler', 'Session', 'Cookie'); 
    var $uses = array('Deal', 'City', 'Partner'); 

    function beforeFilter(){ 
     parent::beforeFilter(); 

     if(strpos($this->here, 'admin')){ 
      $this->layout = 'admin'; 
     } 

    } 

    function view($id = null) { 
     if (!$id) { 
      $this->Session->setFlash(__('Invalid deal', true)); 
      $this->redirect(array('action' => 'index')); 
     } 
     $this->set('deal', $this->Deal->read(null, $id)); 
    } 

    function by_city($CityID = null) 
{ 
    $city = $this->paginate = array(
     'conditions' => array('City.id' => $CityID), 
     'limit' => 1 
    ); 
    $this->set('city',$city); 


    $this->Retailer->recursive = -1; 
    $this->paginate = array(
     'conditions' => array('Deal.city_id' => $CityID), 
     'order' => array('Deal.start'=>'desc'), 
     'limit' => 3 
    ); 
    $this->set('deals',$this->paginate()); 

} 

과 by_city보기를 가질 수 있습니다 : 때 지금

<h3>More Deals from <?php echo $city['City']['city'];?></h3> 

전 이것을 실행하면 "알 수없는 색인 도시"알림이 표시됩니다.

내가 var_dump를 실행할 때 arr 바깥시와 '도시'는 컨트롤러가 더 많은 정보가 필요하면 그냥 물어, 내가

모든 도움을 주시면 감사 롤 지금 잃었어요이

을 통과했다처럼 나에게 소리 값 aswell을 가지고 :

편집 : - :

array(1) { 
    [0]=> 
    array(3) { 
    ["Deal"]=> 
    array(15) { 
     ["id"]=> 
     string(1) "2" 
     ["... this part of is fine so ill hide this part of the var_dump 
    } 
    ["City"]=> 
    array(2) { 
     ["id"]=> 
     string(1) "1" 
     ["city"]=> 
     string(7) "Glasgow" 
    } 
    } 
} 

으로 변경 코드는 여전히 변수 시티 여기

를 식별하지 컨트롤러가 전달되는 것을 보여주기 위해 위해서 var_dump입니다 $ city [ 'City'] [ 'city']가 전달되는 것을 볼 수 있습니다. 당신이 CakePHP를 사용하는 경우, 데이터를 검색하는 그것의 방법을 따라야한다)

감사 데이브

+1

하하 UFO들처럼 ^^ 아마 당신은 "정의되지 않은"을 의미?. .. – mark

+0

var_dump ($ deals)의 출력을 게시 할 수 있습니까? – Ehtesham

+1

그게 무슨 가치가 있는지, 당신은 모델에 대한 명명 규칙을 따르는 것이 좋습니다. cities라는 테이블이있을 경우, 필드 대신 city를 사용하는 대신 name을 사용해야합니다. 그런 다음 City.city 대신 City.name을 쿼리 할 수 ​​있습니다. –

답변

0

을, PS는 내가이 필드의 이름을 변경합니다. 여기에 코드를 변경합니다

function by_city($CityID = null) 
{ 
    $this->paginate = array(
     'conditions' => array('City.id' => $CityID), 
     'order' => array('Deal.start'=>'desc'), 
     'limit' => 3 
    ); 
    $deals = $this->paginate(); 
    $city = $this->City->find('first',array('conditions'=>array('City.id'=>$CityID))); 
    $this->set(compact('deals','city')); 
} 

편집 : 나는 당신이 지금 위의 코드를 확인하고 싶은 참조)

+0

recursive가> = 0이라고 가정하면 - 그렇지 않으면 여기에 containable을 사용하는 것이 더 낫다. – mark

+0

그는 케이크에 익숙하지 않은 것 같다. 그래서 나는 그에게 기본적인 것들을 먼저 보여줄 뿐이다. 그러나 그렇습니다, Containable은 확실히 좋습니다. –

+0

예 :) 물론. 나는 아직도 내 머리를 비웃는다. 그들에게 UFI라고 부를 수 있습니다 - 미확인 비행 색인 ^^ no offense, 형제. – mark