Question

I realize there are tons of tutorials online, I've looked at them, followed them and they work but now I'm trying to create my own model and I seem to be missing something. My problem: When I try to run my indexAction it just displays NULL, I have put data into my table and yes my table does exist. The table name is fit with fit_id being the primary key

Here is my config file

<models>
        <krauskopf_ymm>
            <class>Krauskopf_Ymm_Model</class>
            <resourceModel>ymm_resource</resourceModel>
        </krauskopf_ymm>

        <ymm_resource>
            <class>Krauskopf_Ymm_Model_Resource</class>
            <entities>
                <krauskopf_ymm>
                    <table>fit</table>
                </krauskopf_ymm>
        </entities>
        </ymm_resource>

</models>

Here is my Model, Krauskopf/Ymm/Model/Ymm.php

<?php
class Krauskopf_Ymm_Model_Ymm extends Mage_Core_Model_Abstract{

  public function _construct(){

    $this->_init('krauskopf_ymm/ymm');
  }

 }

Here is my Resource Krauskopf/Ymm/Model/Resource/Ymm.php

<?php
class Krauskopf_Ymm_Model_Resource_Ymm extends Mage_Core_Model_Resource_Db_Abstract{

 protected function _construct(){

    $this->_init('krauskopf_ymm/ymm', 'fit_id');
 }

}

Here is my collection Krauskopf/Ymm/Model/Resource/Ymm/Collection.php

<?php
class Krauskopf_Ymm_Model_Resource_Ymm_Collection extends     Mage_Core_Model_Resource_Db_Collection_Abstract{

  protected function _construct(){
    $this->_init('krauskopf_ymm/ymm');
  }

}

When I try to run my indexAction it just displays NULL, I have put data into my table and yes my table does exist. The table name is fit with fit_id being the primary key

IndexController.php

    public function indexAction(){
    $model = Mage::getModel('krauskopf_ymm/ymm');
    $data = $model->getData(1);
    var_dump($data);

}
Was it helpful?

Solution

Replace $data = $model->getData(1); with

$model->load(1);
$data = $model->getData()
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top