Magento 백엔드 작업 방법을 배우는 중입니다. 모델 클래스 example/event
과 해당 리소스를 만들었습니다. example_event
을 작성한 DB 테이블에 레코드를 추가 할 수 있습니다 (Magento 관리 양식을 통해). 테이블에서 레코드를 검색하는 데 문제가 있습니다. My Gird 클래스는 다음과 같습니다.Grid의 Magento getCollection()이 false를 반환합니다.
class MasteringMagento_Example_Block_Adminhtml_Event_Grid extends Mage_Adminhtml_Block_Widget_Grid {
protected function _prepareCollection() {
$collection = Mage::getModel('example/event')->getCollection();
var_dump($collection); // bool(false)
//$record = Mage::getModel('example/event')->load(1); //id from example_event table
//var_dump($record); // returns object record as expected
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns() {
$this->addColumn('name', array(
'type'=>'text',
'index'=>'name',
'header'=>$this->__('Name')
));
$this->addColumn('start', array(
'type'=>'date',
'index'=>'start',
'header'=>$this->__('Start Date')
));
$this->addColumn('end', array(
'type'=> 'date',
'index'=>'end',
'header'=>$this->__('End Date')
));
return $this;
}
}
$collection = Mage::getModel('example/event')->getCollection()
은 false를 반환합니다. 그러나 $record = Mage::getModel('example/event')->load(1);
을 사용하여 데이터베이스 테이블에서 하나의 레코드를 검색 할 수 있습니다. 여기서 1은 레코드의 ID입니다 (이것은 적어도 내가 작성한 내용이 DB와 통신 할 수 있는지 확인하기위한 위생 검사입니다). 목표는 _prepareColumns()
함수로 작성된 표에 콜렉션을 렌더링하는 것입니다.
다시 Magento 백엔드에서 프로그래밍 할 때 새로운 점이 있지만 계속해서 코드를 반복적으로 읽었는데 왜 내 컬렉션 객체가 비어 있는지 파악할 수 없습니다.
그래서 (1)을로드 할 수 있지만 모든 컬렉션을로드 할 수 없습니까? – sergio
먼저 'var/log' 폴더에서 오류를 확인하십시오. 그런 다음이 파일이 있는지 확인하십시오 :'MasteringMagento/Example/Model/Resource/Event/Collection.php'. 그렇다면 config.xml과'MasteringMagento/Example/Model/Event.php'의 내용을 질문에 게시하십시오. – Marius
@sergio가 맞습니다. – bar1024