gpt4 book ai didi

php - Cakephp不明索引问题

转载 作者:行者123 更新时间:2023-12-03 09:00:28 25 4
gpt4 key购买 nike

嗨,我一直试图让它工作好久了,

我有一个交易 Controller

<?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 View 是:
<h3>More Deals from <?php echo $city['City']['city'];?></h3>

现在,当我运行它时,我会收到“身份不明城市”的通知

当我运行var_dump时,它说有一个数组City,而“city”也有一个值,这对我来说听起来像是 Controller 已经通过了

我现在迷路了

感谢所有帮助,如果您需要更多信息,请询问:)

编辑:更改代码-它仍然不能识别变量城市

这是var_dump以显示 Controller 正在传递它:
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"
}
}
}

如您所见,$ city ['City'] ['city']正在传递。 PS我将更改此字段的名称;)

谢谢
戴夫

最佳答案

如果使用CakePHP,则应遵循其方式来检索数据。将代码更改为此:

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'));
}


编辑:我看到您现在要做什么,请检查上面的代码;)

关于php - Cakephp不明索引问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6906059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com