나는 거래 컨트롤러
<?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를 사용하는 경우, 데이터를 검색하는 그것의 방법을 따라야한다)
감사 데이브
하하 UFO들처럼 ^^ 아마 당신은 "정의되지 않은"을 의미?. .. – mark
var_dump ($ deals)의 출력을 게시 할 수 있습니까? – Ehtesham
그게 무슨 가치가 있는지, 당신은 모델에 대한 명명 규칙을 따르는 것이 좋습니다. cities라는 테이블이있을 경우, 필드 대신 city를 사용하는 대신 name을 사용해야합니다. 그런 다음 City.city 대신 City.name을 쿼리 할 수 있습니다. –