PHP와 젠드 프레임 워크를 처음 사용합니다. 오류를 만났습니다 :Notice : foreach 구문에서 정의되지 않은 인덱스 'itemid'
Notice: Undefined index: itemid in C:\xampp\htdocs\blogshop\application\views\scripts\item\tops.phtml on line 58
나는이 오류가 나타나는 이유를 모르겠습니다.
public function topsAction() //tops action
{
//$tops = new Application_Model_DbTable_Item();
//$tops->getTops();
$item = new Application_Model_DbTable_Item(); //create new Item object
$this->view->item = $item->getTops(); //$this->view->item is pass to index.phtml
}
이것은 내 컨트롤러 코드입니다.
public function getTops()
{
$row = $this->fetchAll('itemtype = "Tops"'); //find Row based on 'Tops'
if (!$row) { //if row can't be found
throw new Exception("Could not find Tops!"); //Catch exception where itemid is not found
}
return $row->toArray();
}
내 데이터베이스에서 카테고리 '탑'이있는 행을 가져 오기위한 모델의 내 getTops 작업입니다.
<?php foreach($this->item as $item) : ?>
<?php echo $this->escape($this->item['itemid']);?> // This is where the error happens
<img src="<?php echo $this->escape($item->image);?>" width="82" height="100">
<?php echo $this->escape($this->item['itemname']);?>
<?php echo $this->escape($this->item['description']);?>
<?php echo $this->escape($this->item['itemtype']);?>
<?php endforeach; ?>
이
내가 내 데이터베이스에있는 모든 행을 표시하려면 코드입니다.
좋아, 이제 작동하지. 고마워요 :) –
@SwapTest 도와 드릴 수있어서 기쁩니다. 그러나 제발, 당신이 사용하고있는 것을 이해하고 시간을내어주십시오. ([foreach] (http://php.net/manual/en/control-structures.foreach.php) 관련 매뉴얼 페이지) 내가해야할 일을 말했고 내 _fix_를 파일에 병합 한 것이 좋지만 왜 그것이 효과가 있는지 이해하지 못한다면, 그것을 할 때 생산 가치가 있습니다. 또한 이것이 좋은 대답이라면 옆에 투명한 _tick_으로 답을 표시하여 독자들이이 대답이 효과가 있다는 것을 알게 될 것입니다. – Whisperity